Skip to content

migueloller/graphql-utilities

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

graphql-utilities

npm version Build Status Coverage Status

Inspired by graph.ql, graphql-tools, and graphql-helpers.

Why?

There are various libraries out there providing utilities for GraphQL and even the reference implementation itself is adding new utilities. So why do we need another one?

None of those libraries let you build GraphQL types using the schema language. This prevents gradual adoption of the tools and makes code separation and isolation a nightmare.

With graphql-utilities it's simple. build makes it extremely simple to build a GraphQL type.

build(`
  type Query {
    ok: Boolean!
  }
`);

/* is equivalent to */

new GraphQLObjectType({
  name: 'Query',
  fields: () => ({
    ok: { type: new GraphQLNonNull(GraphQLBoolean) },
  }),
})

Installation

npm install --save graphql-utilities

Getting Started

import { build } from 'graphql-utilities';

// you can build a type
const Record = build(`
  interface Record {
    id: ID!
  }
`);

// or you can build a schema
const Schema = build(`
  schema {
    query: Query
  }

  type Query {
    ok: Boolean!
  }
`);

TODO

  • Add detailed API docs.
  • Make build configuration interchangeable with types.
  • Allow build to accept a flag to skip inferred schema.

License

MIT