Registry / devops / egg-graphql

egg-graphql

JSON →
library2.8.0jsnpmunverified

Egg.js plugin for integrating GraphQL using Apollo GraphQL Tools and GraphQL Server. Version 2.8.0 supports Egg.js applications with Node >=8.0.0. Provides automatic schema loading from app/graphql directory, integrated DataLoader, custom directives, and GraphiQL development tool. Enables GraphQL-first development by separating schema, resolvers, connectors, and models. Compared to manual GraphQL setup, this plugin offers seamless Egg.js integration with configuration-driven routing, middleware support, and Apollo Server options passthrough. Active maintenance by the Egg.js team.

npm install egg-graphql
INSTALL
IMPORT
SIG · EGG-GRAPHQL
E
egg-graphql
devopsjavascriptv2.8.0
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.

graphql
// In config/plugin.js module.exports = { graphql: { enable: true, package: 'egg-graphql', }, };
const graphql = require('egg-graphql');
egg-graphql is a plugin, not a direct require. It must be configured in config/plugin.js.
graphql middleware
// In config/config.default.js module.exports = { graphql: { router: '/graphql', app: true, agent: false, graphiql: true, }, middleware: ['graphql'], };
app.use(require('egg-graphql'));
Middleware is registered via config.middleware array, not directly in app.js.
Schema files
// app/graphql/user/schema.graphql type Query { user(id: ID!): User } type User { id: ID! name: String }
// Placing schema outside app/graphql // Using .js files with gql template literal (not supported)
Schema files must be placed in app/graphql subdirectories and use .graphql extension. Directly writing schemas in JavaScript with gql tag is not supported; use .graphql files.

Shows minimal setup: install plugin, configure plugin and middleware, create schema and resolver, then query via browser.

// Install // npm i --save egg-graphql // config/plugin.js exports.graphql = { enable: true, package: 'egg-graphql', }; // config/config.default.js exports.graphql = { router: '/graphql', app: true, agent: false, graphiql: true, }; exports.middleware = ['graphql']; // app/graphql/query/schema.graphql type Query { hello: String } // app/graphql/query/resolver.js module.exports = { Query: { hello: () => 'Hello world', }, }; // Start app and navigate to http://localhost:7001/graphql?query={hello}
Debug
Known issues
gotchaPlugin must be enabled in config/plugin.js, not just installed.
fix
Add graphql entry to config/plugin.js with enable: true and package: 'egg-graphql'.
affects: >=1.0.0
gotchaMiddleware must be registered in config.middleware array, otherwise routes are not intercepted.
fix
Add 'graphql' to exports.middleware in config.default.js.
affects: >=1.0.0
gotchaSchema files must use .graphql extension and be placed in app/graphql subdirectories.
fix
Ensure file is named schema.graphql and located under app/graphql/<model>/.
affects: >=1.0.0
gotchaResolver functions must use module.exports, not ES6 exports.
fix
Use module.exports = { Query: { ... } } in resolver.js.
affects: >=1.0.0
Errors
Common errors & fixes
GraphQL schema is not found / Cannot find module 'app/graphql'
Schema files missing or not in correct directory structure.
fix
Ensure schema.graphql files exist under app/graphql/<model>/ and directories are lowercase.
Router 'graphql' not found / 404 on /graphql
Middleware not registered or graphql config missing.
fix
Add 'graphql' to exports.middleware in config.default.js and verify graphql config has router path.
TypeError: Cannot read property 'Query' of undefined
Resolver file exports wrong structure or not loaded.
fix
Export an object with top-level Query/Mutation keys: module.exports = { Query: { ... } }.
Upgrade
Version history
2.8.0latest on npm
Audit
Dependencies
graphql-toolsrequiredCore dependency for building GraphQL schema from schema strings and resolvers
graphql-serverrequiredProvides the GraphQL server implementation to handle query parsing and execution
dataloaderoptionalUsed to batch and cache data fetching operations per request
Agent activity
4 hits · last 30 days
node
4
Resources
egg-graphql — npm install egg-graphql · libregistry