Registry / development / graphql-playground-middleware-koa

graphql-playground-middleware-koa

JSON →
library1.6.22jsnpmunverified

Koa middleware for exposing the GraphQL Playground IDE endpoint. Current stable version is 1.6.22. Maintained as part of the graphql-playground project (formerly graphcool). Key differentiator: provides an interactive GraphQL IDE with subscription support, docs, and collaboration features. Security vulnerability in versions <1.6.15 due to unsanitized user input. Ships TypeScript types. Peer dependency on Koa v2.

npm install graphql-playground-middleware-koa
INSTALL
IMPORT
SIG · GRAPHQL-PLAYGROUND
G
graphql-playground-middleware-koa
developmentjavascriptv1.6.22
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.

default
import koaPlayground from 'graphql-playground-middleware-koa'
const koaPlayground = require('graphql-playground-middleware-koa').default
ESM default import; CJS require returns the function directly
koaPlayground
const koaPlayground = require('graphql-playground-middleware-koa')
const koaPlayground = require('graphql-playground-middleware-koa').koaPlayground
CommonJS require returns the function as module.exports, not as named export
ExpressPlaygroundMiddleware
import type { ExpressPlaygroundMiddleware } from 'graphql-playground-middleware-koa'
const { ExpressPlaygroundMiddleware } = require('graphql-playground-middleware-koa')
Type-only export for TypeScript; not a runtime value

Sets up a Koa server with GraphQL Playground middleware at /playground, pointing to a GraphQL endpoint at /graphql and a WebSocket subscription endpoint.

import Koa from 'koa'; import Router from 'koa-router'; import koaPlayground from 'graphql-playground-middleware-koa'; const app = new Koa(); const router = new Router(); router.all('/playground', koaPlayground({ endpoint: '/graphql', subscriptionEndpoint: 'ws://localhost:4000/graphql', // All versions before 1.6.15: avoid unsanitized user input here })); app.use(router.routes()); app.listen(4000); console.log('GraphQL Playground at http://localhost:4000/playground');
Debug
Known issues
breakingSecurity vulnerability in versions <1.6.15: unsanitized user input passed to koaPlayground(options) can lead to arbitrary code execution
fix
Upgrade to >=1.6.15 or sanitize user input before passing to koaPlayground()
affects: <1.6.15
breakingDefault import in ESM vs CommonJS: require returns the function directly, not an object with default property
fix
Use const koaPlayground = require('graphql-playground-middleware-koa') in CJS, or import without destructuring in ESM
affects: >=1.0.0
gotchaOptions object passed to koaPlayground must not contain functions or non-serializable data, may cause errors
fix
Only pass plain serializable options (endpoint, subscriptionEndpoint, etc.)
affects: >=1.0.0
Errors
Common errors & fixes
require() of ES modules is not supported when importing node_modules/graphql-playground-middleware-koa/index.mjs
Using require() in a Node.js environment that expects ESM, or mixing module systems
fix
Use import instead of require, or ensure your project uses CommonJS throughout
koaPlayground is not a function
Wrong import style: attempted destructured import from default export in CJS
fix
Use const koaPlayground = require('graphql-playground-middleware-koa') without destructuring
TypeError: Cannot read property 'endpoint' of undefined
Options object not provided or undefined
fix
Pass an options object with at least { endpoint: '/graphql' }
Upgrade
Version history
1.6.22latest on npm
Audit
Dependencies
koarequiredPeer dependency required to run the middleware
Agent activity
51 hits · last 30 days
node
44
Resources
graphql-playground-middleware-koa — npm install graphql-playground-middleware-koa · libregistry