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

apollo-server-koa: Respond to OPTIONS #2288

Merged
merged 3 commits into from
Feb 19, 2019
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

### vNEXT

- `apollo-server-koa`: Support OPTIONS requests [PR #2288](https://github.com/apollographql/apollo-server/pull/2288)

### v2.4.2

- `apollo-server-fastify` is now on Apollo Server and lives within the `apollo-server` repository. This is being introduced in a _patch_ version, however it's a _major_ version bump from the last time `apollo-server-fastify` was published under `1.0.2`. [PR #1971](https://github.com/apollostack/apollo-server/pull/1971)
Expand Down
7 changes: 7 additions & 0 deletions packages/apollo-server-koa/src/ApolloServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,12 @@ export class ApolloServer extends ApolloServerBase {

app.use(
middlewareFromPath(path, (ctx: Koa.Context, next: Function) => {
if (ctx.request.method === 'OPTIONS') {
ctx.status = 204;
ctx.body = '';
return;
}

if (this.playgroundOptions && ctx.request.method === 'GET') {
// perform more expensive content-type check only if necessary
const accept = accepts(ctx.req);
Expand All @@ -187,6 +193,7 @@ export class ApolloServer extends ApolloServerBase {
return;
}
}

return graphqlKoa(() => {
return this.createGraphQLServerOptions(ctx);
})(ctx, next);
Expand Down