Skip to content

Commit

Permalink
Use playground default settings when possible (#1516)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
daggerjames authored and martijnwalraven committed Sep 1, 2018
1 parent 34ece75 commit 984c47d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
14 changes: 10 additions & 4 deletions packages/apollo-server-core/src/playground.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down

0 comments on commit 984c47d

Please sign in to comment.