Skip to content

Commit

Permalink
Merge c2fd567 into 2c23b11
Browse files Browse the repository at this point in the history
  • Loading branch information
nnance committed Sep 9, 2016
2 parents 2c23b11 + c2fd567 commit cbf54a9
Show file tree
Hide file tree
Showing 7 changed files with 245 additions and 114 deletions.
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
23 changes: 17 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ Apollo Server is super-easy to set up. Just npm-install apollo-server, write a G

### TypeScript

If you want to build your GraphQL server using TypeScript, Apollo Server is the project for you.
If you want to build your GraphQL server using TypeScript, Apollo Server is the project for you. **NOTE**: All typings mentioned below must be included in your project in order for it to compile.

```sh
npm install apollo-server
typings i -SG dt~express dt~express-serve-static-core dt~serve-static dt~mime dt~hapi dt~cookies dt~koa
typings i -SG dt~express dt~express-serve-static-core dt~serve-static dt~mime dt~hapi dt~boom dt~cookies dt~koa
```

For using the project in JavaScript, just run `npm install --save apollo-server` and you're good to go!
Expand Down 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

0 comments on commit cbf54a9

Please sign in to comment.