npm install --save graphql-types
import * as GraphQL from 'graphql-types'
const fragment = new GraphQL.Fragment('Viewer', [
new GraphQL.Field('name'),
new GraphQL.Field('email'),
])
const query = new GraphQL.Query('viewer', [4], [
new GraphQL.Field('id'),
new GraphQL.Field('profile_picture', [
new GraphQL.Field('uri'),
], null, [ new GraphQL.Call('site', ['mobile']) ]),
], [ fragment ])
Client:
// Serialize the query before sending it
const json = JSON.stringify(query)
Server:
// Deserialize the query
const query = GraphQL.Query.fromJSON(JSON.parse(req.body))
You can dump queries to easily debug them:
fragment.toString() // {email,name}
query.toString() // viewer(4){email,id,name,profile_picture.site(mobile){uri}}