parse-graphql
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
- Fork it!
- Create your feature branch:
git checkout -b my-new-feature
- Commit your changes:
git commit -am 'Add some feature'
- Push to the branch:
git push origin my-new-feature
- 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