Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HAPI Integration Refactor #127

Merged
merged 14 commits into from
Sep 9, 2016
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Changelog

### v0.3.0
* Refactor HAPI integration to improve the API and make the plugins more idiomatic. ([@nnance](https://github.com/nnance)) in
[PR #127](https://github.com/apollostack/apollo-server/pull/127)
* Fixed query batching with HAPI integration. Issue #123 ([@nnance](https://github.com/nnance)) in
[PR #127](https://github.com/apollostack/apollo-server/pull/127)
* Add support for route options in HAPI integration. Issue #97. ([@nnance](https://github.com/nnance)) in
[PR #127](https://github.com/apollostack/apollo-server/pull/127)

### v0.2.6
* Expose the OperationStore as part of the public API. ([@nnance](https://github.com/nnance))
* Support adding parsed operations to the OperationStore. ([@nnance](https://github.com/nnance))
* Expose ApolloOptions as part of the public API.
Expand Down
19 changes: 15 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,10 @@ app.use('/graphql', bodyParser.json(), apolloConnect({ schema: myGraphQLSchema }
app.listen(PORT);
```

### hapi
### HAPI

Now with the HAPI plugins `ApolloHAPI` and `GraphiQLHAPI` you can pass a route object that includes options to be applied to the route. The example below enables CORS on the `/graphql` route.

```js
import hapi from 'hapi';
import { ApolloHAPI } from 'apollo-server';
Expand All @@ -80,9 +83,16 @@ server.connection({
});

server.register({
register: new ApolloHAPI(),
options: { schema: myGraphQLSchema },
routes: { prefix: '/graphql' },
register: ApolloHAPI,
options: {
path: '/graphql',
apolloOptions: {
schema: myGraphQLSchema,
},
route: {
cors: true
}
},
});

server.start((err) => {
Expand All @@ -92,6 +102,7 @@ server.start((err) => {
console.log(`Server running at: ${server.info.uri}`);
});
```

### Koa
```js
import koa from 'koa';
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"babel-polyfill": "^6.9.1",
"babel-preset-es2015": "^6.9.0",
"body-parser": "^1.15.2",
"boom": "^4.0.0",
"chai": "^3.5.0",
"connect": "^3.4.1",
"express": "^4.14.0",
Expand Down
26 changes: 15 additions & 11 deletions src/integrations/hapiApollo.test.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,32 @@
import * as hapi from 'hapi';
import { ApolloHAPI, GraphiQLHAPI } from './hapiApollo';
import { ApolloHAPI, GraphiQLHAPI, HAPIPluginOptions } from './hapiApollo';

import testSuite, { Schema, CreateAppOptions } from './integrations.test';
import testSuite, { Schema } from './integrations.test';

function createApp(options: CreateAppOptions = {}) {
function createApp(createOptions: HAPIPluginOptions) {
const server = new hapi.Server();

server.connection({
host: 'localhost',
port: 8000,
});

options.apolloOptions = options.apolloOptions || { schema: Schema };

server.register({
register: new ApolloHAPI(),
options: options.apolloOptions,
routes: { prefix: '/graphql' },
register: ApolloHAPI,
options: {
apolloOptions: createOptions ? createOptions.apolloOptions : { schema: Schema },
path: '/graphql',
},
});

server.register({
register: new GraphiQLHAPI(),
options: { endpointURL: '/graphql' },
routes: { prefix: '/graphiql' },
register: GraphiQLHAPI,
options: {
path: '/graphiql',
graphiqlOptions: {
endpointURL: '/graphql',
},
},
});

return server.listener;
Expand Down
Loading