Registry / api / graphql-yoga

graphql-yoga

JSON →
library5.21.1jsnpmunverified

GraphQL Yoga is a fully-featured, simple-to-setup GraphQL server library built on top of Envelop and GraphQL.js. Current stable version is 5.21.1. It provides a batteries-included experience with built-in support for subscriptions, file uploads, CORS, and error masking. Released weekly, it differentiates itself from Apollo Server and express-graphql by being framework-agnostic (works with Node.js, Deno, and Cloudflare Workers) and fully modular via Envelop plugins. It is actively maintained by The Guild and the GraphQL Hive team.

npm install graphql-yoga
INSTALL
IMPORT
SIG · GRAPHQL-YOGA
G
graphql-yoga
apijavascriptv5.21.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

createYoga
import { createYoga } from 'graphql-yoga'
const { createYoga } = require('graphql-yoga')
ESM-only since v3; CommonJS require is not supported. Use dynamic import or a bundler.
createServer
import { createServer } from 'node:http'; import { createYoga } from 'graphql-yoga'
import { createYoga } from 'graphql-yoga' with no HTTP server
createYoga() returns a request handler. You must pass it to an HTTP server like Node's http.createServer.
GraphQLSchema
import { GraphQLSchema } from 'graphql'
import { GraphQLSchema } from 'graphql-yoga'
GraphQLSchema is from the 'graphql' package, not from 'graphql-yoga'.

Sets up a minimal GraphQL Yoga server with a single 'hello' query and listens on port 4000.

import { createYoga } from 'graphql-yoga' import { createServer } from 'node:http' const yoga = createYoga({ schema: { typeDefs: ` type Query { hello: String } `, resolvers: { Query: { hello: () => 'Hello world!' } } } }) const server = createServer(yoga) server.listen(4000, () => { console.log('GraphQL Yoga running on http://localhost:4000/graphql') })
Debug
Known issues
breakingIn v3, `createYoga` no longer accepts a `context` option as a function; use the `context` factory in the server options.
fix
Migrate from `context: ({ req }) => ({ user })` to `context: async ({ request }) => ({ user })`.
affects: >=3.0.0
deprecatedUsing `graphql-yoga` with `graphql` < 15.2 is no longer supported.
fix
Upgrade graphql to at least 15.2 or 16.x.
affects: >=5.0.0
gotchaGraphQL Yoga v5 is ESM-only. Using `require('graphql-yoga')` will throw an error.
fix
Use dynamic import (`import('graphql-yoga')`) or ensure project is set to `"type": "module"`.
affects: >=5.0.0
breakingIn v4, `useEnvelopPlugins` was removed; plugins must be passed directly to `createYoga` via the `plugins` option.
fix
Remove `useEnvelopPlugins` and pass plugins array to `createYoga({ plugins: [...] })`.
affects: >=4.0.0
Errors
Common errors & fixes
Error: You need to provide a `schema` or a `modules` option.
createYoga() called without a schema or type definitions.
fix
Pass a valid GraphQL schema or a typeDefs/resolvers object to createYoga().
TypeError: Cannot destructure property 'createYoga' of 'require(...)' as it is undefined.
CommonJS require() used for ESM-only package.
fix
Use import statement: `import { createYoga } from 'graphql-yoga'` or switch to dynamic import.
Error: Listen EADDRINUSE :::4000
Port already in use, typically another server running.
fix
Kill the process using the port or change the port number in server.listen().
Upgrade
Version history
5.21.1latest on npm
Audit
Dependencies
graphqlrequiredPeer dependency; GraphQL.js is required as the core query engine.
Agent activity
31 hits · last 30 days
node
26
OpenAI (training)
1
Resources
graphql-yoga — npm install graphql-yoga · libregistry