Skip to content

ideas/hapi-graphql

Repository files navigation

hapi-graphql

npm Build Status Dependency Status

GraphQL plugin for hapi.

Installation

npm install --save @ideapod/hapi-graphql

Configuration

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 the GraphQLSchema schema instance from graphql-js under the schema property.
    • rootValue: A value to pass as the rootValue to the graphql() function from graphql-js.
    • pretty: If true, 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: {}
    }
  }
};

Usage

Registration

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) => {
  // ...
});

About

GraphQL plugin for hapi.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published