Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

ooflorent/graphql-types

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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}}

About

Experimental Facebook's GraphQL type definitions

Resources

License

Stars

Watchers

Forks

Packages

No packages published