From 984c47d07abef80c439a86ef39de8c6a681e6635 Mon Sep 17 00:00:00 2001 From: Yipeng Zhao Date: Sat, 1 Sep 2018 15:50:10 +0800 Subject: [PATCH] Use playground default settings when possible (#1516) Playground can either use external settings or its default settings (browser settings), in incompatible ways. The original implementation of default settings here would always provide 'settings' for Playground, in turn make its own settings mechanism disabled, with consequences such as altering settings in-browser cannot work as expect. Besides, once the default settings here go different with Playground provided, it would cause other problems. The intention here is to use Playground setting as default, while explicit passing Playground settings in Apollo server would still work with defaults defined here merged. --- CHANGELOG.md | 1 + packages/apollo-server-core/src/playground.ts | 14 ++++++++++---- .../src/__tests__/ApolloServer.test.ts | 1 + 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1f4e264c8c0..ae763c6d964 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,6 +27,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) +- playground would use its own settings as default [#1516](https://github.com/apollographql/apollo-server/pull/1516) - Lambda: Look in event.path first when picking endpoint for GraphQL Playground [#1527](https://github.com/apollographql/apollo-server/pull/1527) - Fix to allow enabling GraphQL Playground in production with custom config [#1495](https://github.com/apollographql/apollo-server/pull/1495) diff --git a/packages/apollo-server-core/src/playground.ts b/packages/apollo-server-core/src/playground.ts index de35a837473..f92e8560fe4 100644 --- a/packages/apollo-server-core/src/playground.ts +++ b/packages/apollo-server-core/src/playground.ts @@ -49,13 +49,19 @@ export function createPlaygroundOptions( const playgroundOverrides = typeof playground === 'boolean' ? {} : playground || {}; + const settingsOverrides = playgroundOverrides.hasOwnProperty('settings') + ? { + settings: { + ...defaultPlaygroundOptions.settings, + ...playgroundOverrides.settings, + }, + } + : { settings: undefined }; + const playgroundOptions: PlaygroundRenderPageOptions = { ...defaultPlaygroundOptions, ...playgroundOverrides, - settings: { - ...defaultPlaygroundOptions.settings, - ...playgroundOverrides.settings, - }, + ...settingsOverrides, }; return playgroundOptions; diff --git a/packages/apollo-server-express/src/__tests__/ApolloServer.test.ts b/packages/apollo-server-express/src/__tests__/ApolloServer.test.ts index cde6547012d..960a1a3528a 100644 --- a/packages/apollo-server-express/src/__tests__/ApolloServer.test.ts +++ b/packages/apollo-server-express/src/__tests__/ApolloServer.test.ts @@ -171,6 +171,7 @@ describe('apollo-server-express', () => { reject(error); } else { expect(body).toMatch('GraphQLPlayground'); + expect(body).not.toMatch('settings'); expect(response.statusCode).toEqual(200); resolve(); }