graph.ql
Faster and simpler technique for creating and querying GraphQL schemas. 100% compatible with the current GraphQL Schema spec.
Video Course
If you're interested in diving deeper into GraphQL, I've created a video course called Building Better APIs with GraphQL.
Features
- 100% compliance with the current GraphQL schema spec
- Support for queries, mutations, and subscriptions
- Input type support
- Variable support
Installation
npm install graph.ql
Example
var Schema = // an object of promises that fetch actual datavar loaders = // create the schemavar schema = // use the schema
graphql-js vs graph.ql
Say we want to create a GraphQL schema that looks like this:
type Film {
title: String
}
type Query {
film(id: Int): Film
}
With the official graphql-js library, it would look like this:
var graphql = var Film = name: 'Film' fields: title: type: graphqlGraphQLString var schema = query: name: 'Query' fields: film: type: Film args: id: description: 'Fetch the film by id' type: graphqlGraphQLInt
With graph.ql
, we just need to do this:
var schema =
FAQ
How do I add descriptions?
- You can add descriptions by placing a comment directly above the field or type. The following shows a comment on a type as well as a comment on a field.
# Query methodstype Query # Fetch the film by id : Film
Credits
Thanks to ForbesLindesay for his initial work on graphql-schema-gen which laid the groundwork for this module.
Thanks to the GraphQL team for an incredible spec as well as their kitchen sink documents to quickly test against the entire spec.
Run Tests
npm install
License
MIT