Nonchalant Programming Master

    graphql-info-parser
    TypeScript icon, indicating that this package has built-in type declarations

    0.0.1-alpha5 • Public • Published

    Graphql Info Parser

    npm version

    Graphql-info-parser helps you to take advantage of the info argument. It transforms the info object into an understandable data structure, with all the necessary information of the query. (Directives, Args). This way, you can for example generate an SQL request from the root resolver.

    • Directives ok
    • Args ok
    • fragments ok
    • interface TODO
    • union TODO
    • extends

    Install

    npm

    npm install --save graphql-info-parser
    

    yarn

    yarn add graphql-info-parser
    

    Usage

    import { infoParser } from 'graphql-info-parser';
     
    const Query = {
      users: (parents, args, ctx, info) => {
        const obj = infoParser(info);
      },
    };

    Example

    • schema.graphql
    type User {
      firstName: String
      lastName: String
      last_name: String @deprecated
      online: Boolean
      friends(limit: Int!): [User]
    }
     
    type Query {
      users: [User]
    }
    • query
    query {
      users {
        firstName
        last_name
        friends(limit: 5) {
          firstName
        }
      }
    }
    • resolver
    import { infoParser } from 'graphql-info-parser';
     
    const Query = {
      users: (parents, args, ctx, info) => {
        const obj = infoParser(info);
      },
    };
    • Result:
    obj = {
      name: 'users',
      type: 'User',
      isList: true,
      args: {},
      directivesObject: {},
      fields: [{
          name: 'firstName',
          type: 'String',
          isList: false,
          args: {},
          directivesObject: {},
          directivesField: {},
        },
        last_name{
          name: 'last_name',
          type: 'String',
          isList: false,
          args: {},
          directivesObject: {},
          directivesField: { deprecated: {} },
        },
        friends{
          name: 'friends',
          type: 'User',
          isList: true,
          args: { limit: 5 },
          directivesObject: {},
          directivesField: {},
          fields: [{
            name: 'firstName',
            type: 'String',
            isList: false,
            args: {},
            directivesObject: {},
            directivesField: {},
          }]
        },
      ]
    };

    Keywords

    none

    Install

    npm i graphql-info-parser

    DownloadsWeekly Downloads

    26

    Version

    0.0.1-alpha5

    License

    MIT

    Unpacked Size

    9.68 kB

    Total Files

    8

    Last publish

    Collaborators

    • lucm