Catch the highlights of GraphQLConf 2023!Click for recordings.Or check out our recap blog post.
This is the documentation for the old GraphQL Yoga version 2. We recommend upgrading to the latest GraphQL Yoga version 5.

Migrate to GraphQL Yoga v5

Integration with Fastify

Fastify (opens in a new tab) is one of the popular HTTP server frameworks for Node.js. It is a very simple, yet powerful framework that is easy to learn and use. You can easily integrate GraphQL Yoga with Fastify.

So you can benefit from the powerful plugins of the Fastify ecosystem with GraphQL Yoga. See the ecosystem (opens in a new tab).


yarn add @graphql-yoga/node fastify graphql


import { createServer } from '@graphql-yoga/node'
import fastify, { FastifyRequest, FastifyReply } from 'fastify'
// This is the fastify instance you have created
const app = fastify({ logger: true })
const graphQLServer = createServer<{
  req: FastifyRequest
  reply: FastifyReply
  // Integrate Fastify logger
  logging: {
    debug: (...args) => args.forEach((arg) => app.log.debug(arg)),
    info: (...args) => args.forEach((arg) =>,
    warn: (...args) => args.forEach((arg) => app.log.warn(arg)),
    error: (...args) => args.forEach((arg) => app.log.error(arg))
 * We pass the incoming HTTP request to GraphQL Yoga
 * and handle the response using Fastify's `reply` API
 * Learn more about `reply`
  url: '/graphql',
  method: ['GET', 'POST', 'OPTIONS'],
  async handler(req, reply) {
    // Second parameter adds Fastify's `req` and `reply` to the GraphQL Context
    const response = await graphQLServer.handleIncomingMessage(req, {
    response.headers.forEach((value, key) => {
      reply.header(key, value)
    return reply

Add Dummy Content Type Parser for File Uploads

Fastify needs to be aware of GraphQL Yoga will handle multipart/form-data requests because otherwise, it will throw an error something like Unsupported media type.

// This will allow Fastify to forward multipart requests to GraphQL Yoga
app.addContentTypeParser('multipart/form-data', {}, (req, payload, done) =>

You can also check a full example on our GitHub repository here (opens in a new tab).