On this page

Integration with Express

GraphQL Yoga v3 documentation (superseded by v5): Express is the most popular web framework for Node.js. It is a minimalist framework that provides a robust set of features to handle HTTP on Node.js applications.

Express is the most popular web framework for Node.js. It is a minimalist framework that provides a robust set of features to handle HTTP on Node.js applications. You can easily integrate GraphQL Yoga into your Express application with a few lines of code.

Installation

npm i express
npm i graphql
npm i graphql-yoga

Example

import express from 'express'
import { createYoga } from 'graphql-yoga'

const app = express()

const yoga = createYoga()

// Bind GraphQL Yoga to the graphql endpoint to avoid rendering the playground on any path
app.use(yoga.graphqlEndpoint, yoga)

app.listen(4000, () => {
  console.log('Running a GraphQL API server at http://localhost:4000/graphql')
})

You can also check a full example on our GitHub repository here