GraphQL Yoga v2 documentation (superseded by v5): GraphQL Yoga is a fully-featured GraphQL Server with focus on easy setup, performance & great developer experience.
Installation
You can start by installing graphql-yoga package.
npm i @graphql-yoga/node
yarn add @graphql-yoga/node
pnpm add @graphql-yoga/node
bun add @graphql-yoga/node
Replace Express GraphQL’s Middleware
You should replace Express GraphQL’s middleware with GraphQL Yoga’s;
const express = require('express')- const { graphqlHTTP } = require('express-graphql')+ const { createServer } = require('@graphql-yoga/node')const { schema } = require('./schema')const app = express()- app.use('/graphql', graphqlHTTP(req => ({- schema: schema,- context: {- token: req.headers.authorization- },- graphiql: true- })))+ const yoga = createServer({+ schema,+ context: (req) => ({ // Context factory gets called for every request+ myToken: req.headers.get('authorization')+ }),+ graphiql: true+ })++ app.use('/graphql', yoga)app.listen(4000)console.log('Running a GraphQL API server at http://localhost:4000/graphql')
This site uses cookies for analytics and improving your experience.