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).
yarn add parse-graphql
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 }
}
git checkout -b my-new-feature
git commit -am 'Add some feature'
git push origin my-new-feature
parse-graphql © EGOIST, Released under the MIT License. Authored and maintained by EGOIST with help from contributors (list).
github.com/egoist · GitHub @EGOIST