Skip to content

Commit

Permalink
Hapi: Pass toolkit to context function (#1407)
Browse files Browse the repository at this point in the history
* Fix for #1382

* fix typo in changelog

* Added a few tests proving the response toolkit is passed into the context function
  • Loading branch information
maxnachlinger authored and Evans Hauser committed Jul 27, 2018
1 parent e514cdf commit 0b76e9e
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -4,6 +4,7 @@ All of the packages in the `apollo-server` repo are released with the same versi

### vNEXT

- Hapi: Pass the response toolkit to the context function. [#1407](https://github.com/apollographql/apollo-server/pull/1407)
- update apollo-engine-reporting-protobuf to non-beta [#1429](https://github.com/apollographql/apollo-server/pull/1429)

### rc.10
Expand Down
27 changes: 27 additions & 0 deletions packages/apollo-server-hapi/src/ApolloServer.test.ts
Expand Up @@ -223,6 +223,33 @@ describe('apollo-server-hapi', () => {
await apolloFetch({ query: '{hello}' });
});

it('passes each request and response toolkit through to the context function', async () => {
const context = async ({ request, h }) => {
expect(request, 'request argument should exist').to.exist;
expect(h, 'response toolkit argument should exist').to.exist;
return {};
};

server = new ApolloServer({
typeDefs,
resolvers,
context,
});
app = new Server({ port: 4000 });

await server.applyMiddleware({ app });
await app.start();

httpServer = app.listener;
const uri = app.info.uri + '/graphql';

const apolloFetch = createApolloFetch({ uri });
const result = await apolloFetch({ query: '{hello}' });

expect(result.data).to.deep.equal({ hello: 'hi' });
expect(result.errors, 'errors should exist').not.to.exist;
});

describe('healthchecks', () => {
afterEach(async () => {
await server.stop();
Expand Down
2 changes: 1 addition & 1 deletion packages/apollo-server-hapi/src/hapiApollo.ts
Expand Up @@ -41,7 +41,7 @@ const graphqlHapi: IPlugin = {
handler: async (request, h) => {
try {
const { graphqlResponse, responseInit } = await runHttpQuery(
[request],
[request, h],
{
method: request.method.toUpperCase(),
options: options.graphqlOptions,
Expand Down

0 comments on commit 0b76e9e

Please sign in to comment.