GraphQL plugin for hapi.
npm install --save @ideapod/hapi-graphql
The 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 theGraphQLSchema
schema instance fromgraphql-js
under theschema
property.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) => {
// ...
});