1.1.0 • Published 9 years ago
graphql-types v1.1.0
graphql-types
Install
npm install --save graphql-types
Usage
Creating queries
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 ])
Serializing
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))
Debugging
You can dump queries to easily debug them:
fragment.toString() // {email,name}
query.toString() // viewer(4){email,id,name,profile_picture.site(mobile){uri}}