Skip to content

Commit

Permalink
Fixed GraphQL Playground with custom configuration in production. (#1495
Browse files Browse the repository at this point in the history
)

* Fixed support for GraphQL Playground with custom configuration in production environments.

* Updated logic in `createPlaygroundOptions` to cast the `playground` option to a boolean
  if it is defined. Fall back to `isDev` logic only if undefined.
* Updated unit test for partial graphql playground options to emulate a 'production'
  environment, mimicking the scenario that was broken before.

* Add PR #1495 to CHANGELOG.

* Restore partial playground options test when no `NODE_ENV`
  • Loading branch information
nderscore authored and evans committed Aug 14, 2018
1 parent 4d67c1c commit 412be20
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ All of the packages in the `apollo-server` repo are released with the same versi
- 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)
- Fix to allow enabling GraphQL Playground in production with custom config [#1495](https://github.com/apollographql/apollo-server/pull/1495)

### rc.10

Expand Down
3 changes: 2 additions & 1 deletion packages/apollo-server-core/src/playground.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ export function createPlaygroundOptions(
playground: PlaygroundConfig = {},
): PlaygroundRenderPageOptions | undefined {
const isDev = process.env.NODE_ENV !== 'production';
const enabled: boolean = typeof playground === 'boolean' ? playground : isDev;
const enabled: boolean =
typeof playground !== 'undefined' ? !!playground : isDev;

if (!enabled) {
return undefined;
Expand Down
24 changes: 19 additions & 5 deletions packages/apollo-server-express/src/__tests__/ApolloServer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,7 @@ describe('apollo-server-express', () => {
});
});

it('accepts partial GraphQL Playground Options', async () => {
const nodeEnv = process.env.NODE_ENV;
delete process.env.NODE_ENV;

const playgroundPartialOptionsTest = async () => {
const defaultQuery = 'query { foo { bar } }';
const endpoint = '/fumanchupacabra';
const { url } = await createServer(
Expand Down Expand Up @@ -220,7 +217,6 @@ describe('apollo-server-express', () => {
},
},
(error, response, body) => {
process.env.NODE_ENV = nodeEnv;
if (error) {
reject(error);
} else {
Expand All @@ -234,8 +230,26 @@ describe('apollo-server-express', () => {
},
);
});
};

it('accepts partial GraphQL Playground Options in production', async () => {
const nodeEnv = process.env.NODE_ENV;
process.env.NODE_ENV = 'production';
await playgroundPartialOptionsTest();
process.env.NODE_ENV = nodeEnv;
});

it(
'accepts partial GraphQL Playground Options when an environment is ' +
'not specified',
async () => {
const nodeEnv = process.env.NODE_ENV;
delete process.env.NODE_ENV;
await playgroundPartialOptionsTest();
process.env.NODE_ENV = nodeEnv;
},
);

it('accepts playground options as a boolean', async () => {
const nodeEnv = process.env.NODE_ENV;
delete process.env.NODE_ENV;
Expand Down

0 comments on commit 412be20

Please sign in to comment.