Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/skarpdev/hapi-graphql-2
Create a GraphQL HTTP server with Hapi v17
https://github.com/skarpdev/hapi-graphql-2
Last synced: 20 days ago
JSON representation
Create a GraphQL HTTP server with Hapi v17
- Host: GitHub
- URL: https://github.com/skarpdev/hapi-graphql-2
- Owner: skarpdev
- Created: 2018-03-16T14:48:50.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2018-09-11T08:30:01.000Z (over 6 years ago)
- Last Synced: 2024-12-16T01:46:30.744Z (about 2 months ago)
- Language: JavaScript
- Homepage:
- Size: 83 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
[![Build Status](https://travis-ci.org/skarpdev/hapi-graphql-2.svg?branch=master)](https://travis-ci.org/skarpdev/hapi-graphql-2)
# GraphQL Hapi PluginCreate a GraphQL HTTP server with [Hapi](http://hapijs.com).
Original code from [SimonDegraeves hapi-graphql](https://github.com/SimonDegraeve/hapi-graphql).```js
npm install --save hapi-graphql-2
```If you are using `yarn`
```js
yarn add hapi-graphql-2
```### Example
```js
const Hapi = require('hapi');
const GraphQL = require('hapi-graphql-2');
const {GraphQLSchema} = require('graphql');const server = new Hapi.Server({
port: 3000
});const TestSchema = new GraphQLSchema({});
await server.register({
plugin: GraphQL,
options: {
query: {
# options, see below
},
// OR
//
// query: (request) => ({
// # options, see below
// }),
route: {
path: '/graphql',
config: {}
}
}
});
await 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:```js
formatError: error => ({
message: error.message,
locations: error.locations,
stack: error.stack
})
```