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

Allow additional Hapi route options to be passed #1384

Merged
merged 5 commits into from
Aug 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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: Allow additional route options to be passed to Hapi.js plugin. [PR #1384](https://github.com/apollographql/apollo-server/pull/1384)
- express, koa: remove next after playground [#1436](https://github.com/apollographql/apollo-server/pull/1436)
- 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)
Expand Down
11 changes: 8 additions & 3 deletions packages/apollo-server-hapi/src/ApolloServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export class ApolloServer extends ApolloServerBase {
app,
cors,
path,
route,
disableHealthCheck,
onHealthCheck,
}: ServerRegistration) {
Expand Down Expand Up @@ -122,9 +123,12 @@ export class ApolloServer extends ApolloServerBase {
options: {
path,
graphqlOptions: this.createGraphQLServerOptions.bind(this),
route: {
cors: cors !== undefined ? cors : true,
},
route:
route !== undefined
? route
: {
cors: cors !== undefined ? cors : true,
},
},
});

Expand All @@ -136,6 +140,7 @@ export interface ServerRegistration {
app?: hapi.Server;
path?: string;
cors?: boolean | hapi.RouteOptionsCors;
route?: hapi.RouteOptions;
onHealthCheck?: (request: hapi.Request) => Promise<any>;
disableHealthCheck?: boolean;
uploads?: boolean | Record<string, any>;
Expand Down
44 changes: 44 additions & 0 deletions packages/apollo-server-hapi/src/__tests__/ApolloServer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,50 @@ describe('apollo-server-hapi', () => {
await apolloFetch({ query: '{hello}' });
});

it('accepts custom route configuration', async () => {
server = new ApolloServer({
typeDefs,
resolvers,
});
app = new Server({
port,
});

await server.applyMiddleware({
app,
route: {
cors: {
additionalExposedHeaders: ['X-Apollo'],
exposedHeaders: [
'Accept',
'Authorization',
'Content-Type',
'If-None-Match',
'Another-One',
],
},
},
});

await app.start();

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

const apolloFetch = createApolloFetch({ uri }).useAfter(
(response, next) => {
expect(
response.response.headers.get('access-control-expose-headers'),
).toEqual(
'Accept,Authorization,Content-Type,If-None-Match,Another-One,X-Apollo',
);
next();
},
);

await apolloFetch({ query: '{hello}' });
});

it('passes each request and response toolkit through to the context function', async () => {
const context = async ({ request, h }) => {
expect(request).toBeDefined();
Expand Down