On this page

Quick Start

GraphQL Yoga v2 documentation (superseded by v5): GraphQL Yoga is a batteries-included cross-platform GraphQL Server using Envelop, and GraphQL Tools that runs anywhere.

GraphQL Yoga is a batteries-included cross-platform GraphQL over HTTP spec-compliant GraphQL Server using Envelop, and GraphQL Tools that runs anywhere.

Installation

npm i @graphql-yoga/node graphql

Usage

You will need to provide a schema to Yoga, either by an existing executable schema or by providing your type definitions and resolver map.

import { createServer } from '@graphql-yoga/node'

const server = createServer({
  schema: {
    typeDefs: /* GraphQL */ `
      type Query {
        hello: String
      }
    `,
    resolvers: {
      Query: {
        hello: () => 'Hello from Yoga!'
      }
    }
  }
})

server.start()

That is it!

Now visit http://localhost:4000/graphql to execute the following query operation:

query HelloWorld {
  hello
}

Using Existing Schema

You can also pass an existing GraphQLSchema instance to createServer.

If you’re using a library such as Pothos, GraphQL Nexus, gqtx, or vanilla graphql-js, you simply can pass the GraphQLSchema to schema:

import { createServer } from '@graphql-yoga/node'
import { schema } from './schema'

const server = createServer({ schema })

server.start()