Skip to content

Commit e565b04

Browse files
fix(): fix defaults settings
1 parent 0582e77 commit e565b04

File tree

1 file changed

+27
-20
lines changed

1 file changed

+27
-20
lines changed

lib/utils/merge-defaults.util.ts

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
UserInputError,
1111
} from 'apollo-server-core';
1212
import { GraphQLError, GraphQLFormattedError } from 'graphql';
13+
import { omit } from 'lodash';
1314
import { GqlModuleOptions } from '../interfaces/gql-module-options.interface';
1415

1516
const defaultOptions: GqlModuleOptions = {
@@ -22,28 +23,34 @@ export function mergeDefaults(
2223
options: GqlModuleOptions,
2324
defaults: GqlModuleOptions = defaultOptions,
2425
): GqlModuleOptions {
25-
if (options.playground !== undefined) {
26-
// Preserve backward compatibility
27-
if (options.playground !== false && process.env.NODE_ENV !== 'production') {
28-
const playgroundOptions =
29-
typeof options.playground === 'object' ? options.playground : undefined;
30-
defaults = {
31-
...defaults,
32-
plugins: [
33-
ApolloServerPluginLandingPageGraphQLPlayground(
34-
playgroundOptions,
35-
) as PluginDefinition,
36-
],
37-
};
38-
} else if (process.env.NODE_ENV === 'production') {
39-
defaults = {
40-
...defaults,
41-
plugins: [ApolloServerPluginLandingPageDisabled() as PluginDefinition],
42-
};
43-
}
26+
if (
27+
(options.playground === undefined &&
28+
process.env.NODE_ENV !== 'production') ||
29+
options.playground
30+
) {
31+
const playgroundOptions =
32+
typeof options.playground === 'object' ? options.playground : undefined;
33+
defaults = {
34+
...defaults,
35+
plugins: [
36+
ApolloServerPluginLandingPageGraphQLPlayground(
37+
playgroundOptions,
38+
) as PluginDefinition,
39+
],
40+
};
41+
} else if (
42+
(options.playground === undefined &&
43+
process.env.NODE_ENV === 'production') ||
44+
options.playground === false
45+
) {
46+
defaults = {
47+
...defaults,
48+
plugins: [ApolloServerPluginLandingPageDisabled() as PluginDefinition],
49+
};
4450
}
51+
4552
const moduleOptions = {
46-
...defaults,
53+
...omit(defaults, 'plugins'),
4754
...options,
4855
};
4956
moduleOptions.plugins = (moduleOptions.plugins || []).concat(

0 commit comments

Comments
 (0)