npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

gqlimp

v0.3.8

Published

Graphql Client Generator

Downloads

3

Readme

gqlimp

NPM Version NPM Downloads Build Status Test Coverage Dependencies DevDependencies

NPM

Gqlimp is an executable npm package created for client applications that communicate with the graphql server. The reasons to create this tool are to accelerate development of server applications coded with graphql in the client part and to increase client - server interaction.

It is intended that the query scheme created on the graphql server can be used easily and accurately in the client application via Gqlimp.Thanks to perform programmatic processing when creating a query, it can be developped code more flexible and faster in client side.

When there is a change in the query scheme created on the server, the client will be aware of this change and will have to make the necessary arrangements thanks to the import mechanism.

Installation

$ npm install gqlimp

Features

Parameters Guide

  • url: Graphql server url (required).
  • fileName: Name of imported file (default: "schema-all").
  • generate: To create a schema client file (optional).
  • verbose: To view details of schema types (optional).
  • output: Folder path of output (default: "output").
  • properties: To import chosen specific properties (default: "all" - options: "enums", "interfaces", "inputs", "customScalars", "helpers", "args").
  • type: File type of output (default: "ts" - options: for javascript -> "js", for typescript -> "ts").
  • realType: To add real field types (default: false)
  • compileTarget: It is used when type parameter is "js" (default: "es5" - options: "es5", "es6", "es2016", "es2017", "esnext" ).
  • compileLib: It is used when type parameter is "js" (default: "esnext" - options: "es5", "es6", "es2016", "es2017", "esnext" ).

Generated File Properties

There are 2 basic public classes in the file created with gqlimp. Depending on the type of query to be used, one of the following classes is selected as root and the structure of the query is created.

  • QueryObject Class
    • Properties
      • query: string
      • args: any
  • MutationObject Class
    • Properties
      • query: string

      • args: any

How to work "gqlimp" tool?

Example of Gqlimp tool:   Gqlimp requires a graphql server to create the client file.

Step - 1: You need a graphql server. (sample url -> http://localhost:5000/api)

  type Phone {
    gsm: String
    note: String
  }

  type User {
    id: Int
    name: String  
    phone: Phone       
  }
  
  type Query {    
    user(id: Int!): User     
  }
  
  input PhoneInput {
    gsm: String
    note: String
  }  
  
  input UserInput {
    name: String  
    phone: PhoneInput    
  } 
  
  type Mutation {
    createUser(user: UserInput): User
  }    
  

Let's assume that the Graphql server contains inputs and types in step-1. To import these schema types using the Gqlimp tool, the command in step-2 must be executed.

Step - 2: Execute command:
$ gqlimp --url http://localhost:5000/api -g

After running the command, the client file is created in the output folder.

Step - 3: File view generated by "gqlimp" (schema-all.ts).

  export interface Phone_intf {
    gsm? : boolean | number;
    note? : boolean | number;
  }

  export interface User_intf {
    id? : boolean | number;
    name? : boolean | number;
    phone? : User_phone;	
  } 

  export interface Query_intf {
    user? : Query_user;
  }
  
  export interface Mutation_intf {
    createUser? : Mutation_createUser;
  }
  
  /*
  export class QueryObject ...
  
  export class MutationObject ...
  
  export class Query_user ...
  
  export class User_phone ...
  
  export class Mutation_createUser ...
  */

The structure of the generated file is like the structure of the fields on the graphql server. Gqlimp has created a class for each field.

Step - 4: Usage of client "schema-all.ts" file

Query Example:


  import { QueryObject } from './schema-all';
    
  const qo = new QueryObject({
    user: new Query_user({
      id: true,
      name: true,
      phone: new User_phone({
        gsm: true,
        note: true
      })  
    })
  });
  
  console.log(qo.query);
  /* Output
  query {
    user {
      id
      name
      phone {
        gsm
        note
      }
    }
  }
  */

Mutation Example:


  import { QueryObject } from './schema-types';
    
  const qo = new MutationObject({
    createUser: new Mutation_createUser({     
      name: 'User 1',
      phone: {
        gsm: 'User Gsm',
        note: 'Note'
      }  
    },
    {
      id: true,
      name: true      
    })
  });
  
  console.log(qo.query);
  /* Output
    mutation ($name: String, $phone: PhoneInput) {
      createUser(name: $name, phone: $phone ) {
        id
        name
      }
    }
  
  console.log(qo.args);
  /* Output
    {
      name: 'User 1',
      phone: {
        gsm: 'User Gsm',
        note: 'Note'
      }
    }
  */

In above examples, QueryObject class starts as root. This root object gives fields that can be queried.

These fields expect the object of their class. After defining the fields to be used, The QueryObject.query / MutationObject.query property gives a string query. If there is an argument in the generated query these arguments are accessed with QueryObject.args / MutationObject.args.

Node Compatibility

  • node >= 6.x;

License

MIT