Catch the highlights of GraphQLConf 2023!Click for recordings.Or check out our recap blog post.
v5 (latest)
Quick Start

Quick start

GraphQL Yoga is a batteries-included cross-platform GraphQL over HTTP spec-compliant (opens in a new tab) GraphQL server powered by Envelop (opens in a new tab) and GraphQL Tools (opens in a new tab) that runs anywhere; focused on easy setup, performance and great developer experience.

Installation

npm i graphql-yoga graphql

Schema

You will need to provide a schema to Yoga, there are many ways to assemble a GraphQL schema, here's just a few:

Use the createSchema function included in Yoga. It actually reuses the makeExecutableSchema from @graphql-tools/schema (opens in a new tab).

schema.js
import { createSchema } from 'graphql-yoga'
 
export const schema = createSchema({
  typeDefs: /* GraphQL */ `
    type Query {
      hello: String
    }
  `,
  resolvers: {
    Query: {
      hello: () => 'world'
    }
  }
})

Get the best developer experience!

GraphQL Code Generator and its server preset can help you build type-safe and scalable GraphQL servers.

Check out GraphQL Code Generator (opens in a new tab), then read how to set up GraphQL server with server preset (opens in a new tab).

Server

After you have created a GraphQL schema, simply pass it in to Yoga and liftoff! 🚀

import { createServer } from 'node:http'
import { createYoga } from 'graphql-yoga'
import { schema } from './schema'
 
// Create a Yoga instance with a GraphQL schema.
const yoga = createYoga({ schema })
 
// Pass it into a server to hook into request handlers.
const server = createServer(yoga)
 
// Start the server and you're done!
server.listen(4000, () => {
  console.info('Server is running on http://localhost:4000/graphql')
})

Visit http://localhost:4000/graphql (opens in a new tab) to see Yoga in action.