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: Pass toolkit to context function #1407

Merged
merged 11 commits into from
Jul 27, 2018
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@evans This seems like a better test, what do you think?

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
Original file line number Diff line number Diff line change
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