Skip to content

LucM/graphql-info-parser

Repository files navigation

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: {},
      }]
    },
  ]
};

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published