Skip to content
Parse GraphQL Query.
Branch: master
Clone or download
Latest commit 4b49f99 May 12, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src
.editorconfig
.gitattributes
.gitignore
.prettierrc feat: init May 12, 2019
LICENSE feat: init May 12, 2019
README.md
circle.yml
package.json
rollup.config.js
yarn.lock

README.md

parse-graphql

NPM version NPM downloads CircleCI donate chat

Given a GraphQL source, parses it into a Document.

Throws GraphQLError if a syntax error is encountered.

This module is basically a standalone version (70KB unminified) for require('graphql').parse (1.8MB).

Install

yarn add parse-graphql

Usage

const { parse } = require('parse-graphql')

const document = parse(`{
  user {
    name
    id
  }
}`)

The document is:

{
  kind: 'Document',
  definitions: [
    {
      kind: 'OperationDefinition',
      operation: 'query',
      name: undefined,
      variableDefinitions: [],
      directives: [],
      selectionSet: {
        kind: 'SelectionSet',
        selections: [
          {
            kind: 'Field',
            alias: undefined,
            name: { kind: 'Name', value: 'user', loc: { start: 4, end: 8 } },
            arguments: [],
            directives: [],
            selectionSet: {
              kind: 'SelectionSet',
              selections: [
                {
                  kind: 'Field',
                  alias: undefined,
                  name: {
                    kind: 'Name',
                    value: 'name',
                    loc: { start: 15, end: 19 }
                  },
                  arguments: [],
                  directives: [],
                  selectionSet: undefined,
                  loc: { start: 15, end: 19 }
                },
                {
                  kind: 'Field',
                  alias: undefined,
                  name: {
                    kind: 'Name',
                    value: 'id',
                    loc: { start: 24, end: 26 }
                  },
                  arguments: [],
                  directives: [],
                  selectionSet: undefined,
                  loc: { start: 24, end: 26 }
                }
              ],
              loc: { start: 9, end: 30 }
            },
            loc: { start: 4, end: 30 }
          }
        ],
        loc: { start: 0, end: 32 }
      },
      loc: { start: 0, end: 32 }
    }
  ],
  loc: { start: 0, end: 32 }
}

Contributing

  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Commit your changes: git commit -am 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request :D

Author

parse-graphql © EGOIST, Released under the MIT License.
Authored and maintained by EGOIST with help from contributors (list).

github.com/egoist · GitHub @EGOIST

You can’t perform that action at this time.