graphql-types

1.1.0 • Public • Published

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

Readme

Keywords

Package Sidebar

Install

npm i graphql-types

Weekly Downloads

32

Version

1.1.0

License

MIT

Last publish

Collaborators

  • ooflorent