From 8ca738034779c5689441c9890fa8d1c9836e3f64 Mon Sep 17 00:00:00 2001 From: Sashko Stubailo Date: Mon, 13 Aug 2018 12:58:23 -0700 Subject: [PATCH] Look in event.path first when selecting endpoint for GraphQL Playground on Lambda, and check for null (#1527) * Look in event.path first, and check for null See here: https://docs.aws.amazon.com/lambda/latest/dg/eventsources.html#eventsources-api-gateway-request * Add to changelog --- CHANGELOG.md | 1 + packages/apollo-server-lambda/src/ApolloServer.ts | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 402eb2003f4..175752ef338 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ All of the packages in the `apollo-server` repo are released with the same versi - 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) +- Lambda: Look in event.path first when picking endpoint for GraphQL Playground [#1527](https://github.com/apollographql/apollo-server/pull/1527) ### rc.10 diff --git a/packages/apollo-server-lambda/src/ApolloServer.ts b/packages/apollo-server-lambda/src/ApolloServer.ts index 94a58c059dc..1949a43f25f 100644 --- a/packages/apollo-server-lambda/src/ApolloServer.ts +++ b/packages/apollo-server-lambda/src/ApolloServer.ts @@ -119,8 +119,13 @@ export class ApolloServer extends ApolloServerBase { if (this.playgroundOptions && event.httpMethod === 'GET') { const acceptHeader = event.headers['Accept'] || event.headers['accept']; if (acceptHeader && acceptHeader.includes('text/html')) { + const path = + event.path || + (event.requestContext && event.requestContext.path) || + '/'; + const playgroundRenderPageOptions: PlaygroundRenderPageOptions = { - endpoint: event.requestContext.path, + endpoint: path, ...this.playgroundOptions, };