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.
This commit is contained in:
Yipeng Zhao 2018-09-01 15:50:10 +08:00 committed by Martijn Walraven
parent 34ece7552b
commit 984c47d07a
3 changed files with 12 additions and 4 deletions

View file

@ -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)

View file

@ -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;

View file

@ -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();
}