ooflorent / graphql-types

Experimental Facebook's GraphQL type definitions

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

License:MIT License


Languages

Language:JavaScript 100.0%