graphql-js 0,4,23,0,24,12,14,0 eslint flowtype travis-ci npm

A reference implementation of GraphQL for JavaScript


The JavaScript reference implementation for GraphQL, a query language for APIs created by Facebook.

npm version Build Status Coverage Status

See more complete documentation at and

Looking for help? Find resources from the community.

Getting Started

An overview of GraphQL in general is available in the README for the Specification for GraphQL. That overview describes a simple set of GraphQL examples that exist as tests in this repository. A good way to get started with this repository is to walk through that README and the corresponding tests in parallel.

Using GraphQL.js

Install GraphQL.js from npm

With yarn:

yarn add graphql

or alternatively using npm:

npm install --save graphql

GraphQL.js provides two important capabilities: building a type schema, and serving queries against that type schema.

First, build a GraphQL type schema which maps to your code base.

import {
} from 'graphql';

var schema = new GraphQLSchema({
  query: new GraphQLObjectType({
    name: 'RootQueryType',
    fields: {
      hello: {
        type: GraphQLString,
        resolve() {
          return 'world';

This defines a simple schema with one type and one field, that resolves to a fixed value. The resolve function can return a value, a promise, or an array of promises. A more complex example is included in the top level tests directory.

Then, serve the result of a query against that type schema.

var query = '{ hello }';

graphql(schema, query).then(result => {

  // Prints
  // {
  //   data: { hello: "world" }
  // }


This runs a query fetching the one field defined. The graphql function will first ensure the query is syntactically and semantically valid before executing it, reporting errors otherwise.

var query = '{ boyhowdy }';

graphql(schema, query).then(result => {

  // Prints
  // {
  //   errors: [
  //     { message: 'Cannot query field boyhowdy on RootQueryType',
  //       locations: [ { line: 1, column: 3 } ] }
  //   ]
  // }


Want to ride the bleeding edge?

The npm branch in this repository is automatically maintained to be the last commit to master to pass all tests, in the same form found on npm. It is recommend to use builds deployed npm for many reasons, but if you want to use the latest not-yet-released version of graphql-js, you can do so by depending directly on this branch:

npm install [email protected]://


We actively welcome pull requests, learn how to contribute.


Changes are tracked as Github releases.


GraphQL is BSD-licensed. We also provide an additional patent grant.

Related Repositories



A reference implementation of GraphQL for JavaScript ...



:wrench: Build and mock your GraphQL.js schema using the schema language ...



A library to help construct a graphql-js server supporting react-relay. ...



Example GraphQL server with Mongoose (MongoDB) and Node.js ...



:wrench: Build and mock your GraphQL.js schema using the schema language ...

Top Contributors

leebyron dschafer schrockn enaqx JeffRMoore andimarek freiksenet swolchok skevy nemanja-stanarevic josephsavona nodkz lacker robzhu facebook-github-whois-bot-0 dminkovsky plievone iamchenxin philix gabrielf wincent hzoo chapel jhgg helfer chentsulin jmandel OlegIlyenko fson kassens


package version
iterall ^1.1.0
dev babel-cli 6.24.1
babel-eslint 7.2.3
babel-plugin-syntax-async-functions 6.13.0
babel-plugin-syntax-async-generators 6.13.0
babel-plugin-transform-class-properties 6.24.1
babel-plugin-transform-flow-strip-types 6.22.0
babel-plugin-transform-object-rest-spread 6.23.0
babel-preset-env ^1.5.2
chai 4.1.0
chai-json-equal 0.0.1
chai-spies-next ^0.8.0
chai-subset 1.5.0
coveralls 2.13.1
eslint 4.3.0
eslint-plugin-babel 4.1.2
eslint-plugin-flowtype 2.35.0
flow-bin 0.52.0
isparta 4.0.0
mocha 3.5.0
sane 2.0.0


-   v0.7.0 zip tar
-   v0.6.2 zip tar
-   v0.6.1 zip tar
-   v0.6.0 zip tar
-   v0.5.0 zip tar
-   v0.5.0-beta.1 zip tar
-   v0.4.18 zip tar
-   v0.4.17 zip tar
-   v0.4.16 zip tar
-   v0.4.15 zip tar
-   v0.4.14 zip tar
-   v0.4.13 zip tar
-   v0.4.12 zip tar
-   v0.4.11 zip tar
-   v0.4.10 zip tar
-   v0.4.9 zip tar
-   v0.4.8 zip tar
-   v0.4.7 zip tar
-   v0.4.6 zip tar
-   v0.4.5 zip tar
-   v0.4.4 zip tar
-   v0.4.3 zip tar
-   v0.4.2 zip tar
-   v0.4.1 zip tar
-   v0.3.0 zip tar
-   v0.2.6 zip tar
-   v0.2.5 zip tar
-   v0.2.4 zip tar
-   v0.2.3 zip tar
-   v0.2.2 zip tar