GraphQL Yoga v3 documentation (superseded by v5): GraphQL Yoga makes no assumptions about the schema building library you want to use.
GraphQL Yoga makes no assumptions about the schema building library you want to use. Whether you’re
using a library such as Pothos, GraphQL Nexus,
gqtx, or vanilla
graphql-js, as long as it provides you with
a GraphQLSchema to schema, you can pass it to GraphQL Yoga.
Providing a Schema
Simply pass an schema to the schema option:
Provide a conditional schema
import { createServer } from 'node:http'import { createYoga } from 'graphql-yoga'import { schema } from './schema.js'const yoga = createYoga({ schema })const server = createServer(yoga)// Start the server and you're done!server.listen(4000, () => { console.info('Server is running on http://localhost:4000/graphql')})
Conditional Schema
You can also pass a factory function for your schema that can return a Promise. The factory
function is invoked for every GraphQL request.
Provide a sync conditional schema
import { createServer } from 'node:http'import { createYoga } from 'graphql-yoga'import { getSchemaForViewer } from './schema.js'const yoga = createYoga({ schema: async request => getSchemaForViewer(request.headers.get('x-schema') ?? 'default')})const server = createServer(yoga)// Start the server and you're done!server.listen(4000, () => { console.info('Server is running on http://localhost:4000/graphql')})
This site uses cookies for analytics and improving your experience.