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

azachii-gql-generator

v0.0.32

Published

Build a gql query easy and avoid typo and schema errors.

Downloads

1

Readme

gql-generator

Build a gql query easy and avoid typo and schema errors.

Installation

npm install --save-dev gql-generator

Required packages

npm install --save graphql graphql-tag

Usage

This package provides control of gql files to dynamic add fields, operations, args, etc.

GQLGenerator

These class save the path of files and the schema to further validations.

initialize

Here we have to tell the graphql endpoint and the path of the query and mutation files. If we don't pass the path of files, this package is going to create them with querys.js and mutations.js names.

|Param|Type|Kind| |---|---|---| |client|String or ApolloClient|Required| |queryFile|String|Optional| |mutationFile|String|Optional|

import GQLGenerator from '@azachii/gql-generator';

await GQLGenerator.initialize(
  'http://localhost:3000',
  './lib/apollo/querys.js',
  './lib/apollo/mutations.js',
);

Files should look like this:

import gql from 'graphql-tag';

GQLBuilder

Here were going to find the operations to manipulate the files.

createQueryFile / createMutationFile

This is how we can manually create the files.

|Param|Type|Kind| |---|---|---| |fileName|String|Required|

import { GQLBuilder } from '@azachii/gql-generator';

GQLBuilder.createQueryFile('./lib/apollo/myQuerys.js');
GQLBuilder.createMutationFile('./lib/apollo/myMutations.js');

createQuery / createMutation

This is what we must call to add a query or mutation to our files.

|Param|Type|Kind| |---|---|---| |name|String|Required| |variables|Object or Array|Optional| |fields|String, Object or Array| Optional|

  • variables:
    • Object:
      • name: String (Required)
      • type: String, must contain a valid GraphQLType (Required)
    • Array: must contain objects with same structure as above
  • fields:
    • String: name of the field
    • Object:
      • name: String (Required)
      • fields: Same structure as parent (Optional)
      • args:
        • String: name of arg, should have a variable name (Required)
        • Array: must contain objects with same structure as above
    • Array: must contain objects with same structure as above
import { GQLBuilder } from '@azachii/gql-generator';

await GQLBuilder.createQuery(
  'authQuery',
  null,
  [
    {
      name: 'currentUser',
      fields: {
        name: 'user',
        fields: [
          'name',
          'lastName',
        ],
      },
    },
  ],
);
await GQLBuilder.createMutation(
  'signUpUser',
  [
    {
      name: 'email',
      type: 'String!',
    },
    {
      name: 'password',
      type: 'String!',
    },
  ],
  {
    name: 'createUser',
    args: [
      'email',
      'password',
    ],
    fields: [
      'token',
      {
        name: 'user',
        fields: [
          'name',
          'lastName',
        ],
      },
    ],
  },
);

And the result would be:

import gql from 'graphql-tag';

const authQuery = gql`query authQuery { currentUser { user { name, lastName } } }`;

export { authQuery };
import gql from 'graphql-tag';

const signUpUser = gql`mutation signUpUser($email: String!, password: String!) { createUser(email: $email, password: $password) { token, user: { name, lastName } } }`;

export { signUpUser };

removeQuery / removeMutation

This allows us to erase a query or mutation.

|Param|Type|Kind| |---|---|---| |name|String|Required|

import { GQLBuilder } from '@azachii/gql-generator';

await GQLBuilder.removeQuery('authQuery');
await GQLBuilder.removeMutation('signUpUser');

addQueryField / addMutationField

If we want to add a field to a query or mutation, this is the way.

|Param|Type|Kind| |---|---|---| |operationName|String|Required| |field|String or Object|Required|

  • field:
    • String: field name
    • Object:
      • name: String (Required)
      • inside: Array of strings, the fields where the field is inside of
import { GQLBuilder } from '@azachii/gql-generator';

await GQLBuilder.addQueryField(
  'authQuery',
  {
    name: 'email',
    inside: [
      'currentUser',
      'user'
    ]
  }
);
await GQLBuilder.addMutationField(
  'signUpUser',
  {
    name: 'email',
    inside: [
      'createUser',
      'user'
    ],
  }
);

removeQueryField / removeMutationField

This is the way to remove a field from a query or mutation.

|Param|Type|Kind| |---|---|---| |operationName|String|Required|

|field|String or Object|Required|

import { GQLBuilder } from '@azachii/gql-generator';

await GQLBuilder.removeQueryField(
  'authQuery',
  {
    name: 'lastName',
    inside: [
      'currentUser',
      'user'
    ]
  }
);
await GQLBuilder.removeMutationField(
  'signUpUser',
  {
    name: 'lastName',
    inside: [
      'createUser',
      'user'
    ],
  }
);

addQueryVariable / addMutationVariable

Add variables to our query or mutation.

|Param|Type|Kind| |---|---|---| |operation|String|Required| |variable|Object|Required|

  • variable:
    • name: Variable name (String)
    • type: GraphQL variable type (String)
import { GQLBuilder } from '@azachii/gql-generator';

await GQLBuilder.addQueryVariable(
  'authQuery',
  {
    name: 'device',
    type: 'DEVICE_TYPE!',
  }
);
await GQLBuilder.addMutationVariable(
  'signUpUser',
  {
    name: 'phone',
    type: 'String',
  }
);

removeQueryVariable / removeMutationVariable

Remove variables from query or mutation

|Param|Type|Kind| |---|---|---| |operation|String|Required| |variable|String|Required|

import { GQLBuilder } from '@azachii/gql-generator';

await GQLBuilder.removeQueryVariable('authQuery', 'device');
await GQLBuilder.removeMutationVariable('signUpUser', 'phone');

TODO

  • addQueryFieldArg
  • addMutationFieldArg
  • removeQueryFieldArg
  • removeMutationFieldArg

MIT © Azachii