GraphQL.js

16.13.2 · active · verified Sat Apr 18

GraphQL.js is the JavaScript reference implementation of the GraphQL specification. It provides a robust and flexible GraphQL runtime and query language parser, enabling developers to build GraphQL servers and clients. The current stable version is 16.13.2, with active development on the next major version 17.0.0, which frequently releases alpha versions and introduces breaking changes.

Common errors

Warnings

Install

Imports

Quickstart

This example demonstrates how to define a simple GraphQL schema, provide a resolver, and execute a basic query using GraphQL.js.

import { graphql, buildSchema } from 'graphql';

// Construct a schema, using GraphQL schema language
const schema = buildSchema(`
  type Query {
    hello: String
  }
`);

// The root provides a resolver function for each API endpoint
const root = {
  hello: () => {
    return 'Hello world!';
  },
};

// Run the GraphQL query '{ hello }' and print out the response
graphql({ schema, source: '{ hello }', rootValue: root }).then((response) => {
  console.log(response);
});

view raw JSON →