0.5.7 • Published 8 years ago

hapi-graphql-updated v0.5.7

Weekly downloads
1
License
MIT
Repository
github
Last release
8 years ago

GraphQL Hapi Plugin

This is a fork of hapi-graphql which addresses some problems and uses an updated version of GraphQL.

Create a GraphQL HTTP server with Hapi. Port from express-graphql.

npm install --save hapi-graphql-updated

Example

import Hapi from 'hapi';
import GraphQL from 'hapi-graphql';
import {GraphQLSchema} from 'graphql';

const server = new Hapi.Server();
server.connection({
  port: 3000
});

const TestSchema = new GraphQLSchema({});

server.register({
  register: GraphQL,
  options: {
    query: {
      schema: TestSchema,
      rootValue: {},
      pretty: false
    },
    // OR
    //
    // query: (request) => ({
    //   schema: TestSchema,
    //   rootValue: {},
    //   graphiql: true,
    // })
    route: {
      path: '/graphql',
      config: {}
    }
  }
}, () =>
  server.start(() =>
    console.log('Server running at:', server.info.uri)
  )
);

Options

The options key of query accepts the following:

  • schema: A GraphQLSchema instance from graphql-js. A schema must be provided.

  • context: A value to pass as the context to the graphql() function from graphql-js.

  • 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.

  • formatError: An optional function which will be used to format any errors produced by fulfilling a GraphQL operation. If no function is provided, GraphQL's default spec-compliant formatError function will be used.

  • validationRules: Optional additional validation rules queries must satisfy in addition to those defined by the GraphQL spec.

  • graphiql: If true, may present GraphiQL when loaded directly from a browser (a useful tool for debugging and exploration).

Debugging

During development, it's useful to get more information from errors, such as stack traces. Providing a function to formatError enables this:

formatError: error => ({
  message: error.message,
  locations: error.locations,
  stack: error.stack
})
0.5.7

8 years ago

0.5.6

8 years ago

0.5.5

8 years ago

0.5.4

8 years ago

0.5.3

8 years ago

0.5.2

8 years ago

0.5.1

8 years ago

0.5.0

8 years ago