GraphQL plugin for hapi.
npm install --save @ideapod/hapi-graphqlThe plugin accepts an options object where:
query: Query configuration object.schema: Name of the plugin which contains the GraphQL schema. Required. Plugin has to expose theGraphQLSchemaschema instance fromgraphql-jsunder theschemaproperty.rootValue: A value to pass as the rootValue to thegraphql()function fromgraphql-js.pretty: Iftrue, any JSON response will be pretty-printed.
route: Route configuration object.path: Path of the GraphQL endpoint. Defaults to/graphql.config: Additional route options.
const plugin = {
register: HapiGraphQL,
options: {
query: {
schema: 'src/graphql/schema',
rootValue: {},
pretty: false
},
route: {
path: '/graphql',
config: {}
}
}
};The plugin can be registered as a hapi plugin. Example:
const Hapi = require('hapi');
const HapiGraphQL = require('@ideapod/hapi-graphql');
const server = new Hapi.Server();
server.connection();
const plugin = {
register: HapiGraphQL,
options: {
query: {
schema: 'src/graphql/schema'
}
}
};
server.register(plugin, (err) => {
// ...
});