Skip to content

Commit a5269f0

Browse files
authored
fix: GraphQL introspection disabled in NODE_ENV=production even with master key (#10071)
1 parent 3148b5f commit a5269f0

2 files changed

Lines changed: 52 additions & 8 deletions

File tree

spec/ParseGraphQLServer.spec.js

Lines changed: 49 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -685,9 +685,16 @@ describe('ParseGraphQLServer', () => {
685685
}
686686
});
687687

688-
it('should always work with master key', async () => {
689-
const introspection =
690-
await apolloClient.query({
688+
it('should always work with master key in node environment production', async () => {
689+
const originalNodeEnv = process.env.NODE_ENV;
690+
try {
691+
// Apollo Server have changing behavior based on the NODE_ENV variable
692+
// so we need to set it to production to get the expected behavior
693+
// and cover correctly the introspection cases
694+
process.env.NODE_ENV = 'production';
695+
await createGQLFromParseServer(parseServer);
696+
697+
const introspection = await apolloClient.query({
691698
query: gql`
692699
query Introspection {
693700
__schema {
@@ -701,10 +708,45 @@ describe('ParseGraphQLServer', () => {
701708
headers: {
702709
'X-Parse-Master-Key': 'test',
703710
},
704-
}
705-
},)
706-
expect(introspection.data).toBeDefined();
707-
expect(introspection.errors).not.toBeDefined();
711+
},
712+
});
713+
expect(introspection.data).toBeDefined();
714+
expect(introspection.errors).not.toBeDefined();
715+
} finally {
716+
process.env.NODE_ENV = originalNodeEnv;
717+
}
718+
});
719+
720+
it('should always work with master key in node environment development', async () => {
721+
const originalNodeEnv = process.env.NODE_ENV;
722+
try {
723+
// Apollo Server have changing behavior based on the NODE_ENV variable
724+
// so we need to set it to development to get the expected behavior
725+
// and cover correctly the introspection cases
726+
process.env.NODE_ENV = 'development';
727+
await createGQLFromParseServer(parseServer);
728+
729+
const introspection = await apolloClient.query({
730+
query: gql`
731+
query Introspection {
732+
__schema {
733+
types {
734+
name
735+
}
736+
}
737+
}
738+
`,
739+
context: {
740+
headers: {
741+
'X-Parse-Master-Key': 'test',
742+
},
743+
},
744+
});
745+
expect(introspection.data).toBeDefined();
746+
expect(introspection.errors).not.toBeDefined();
747+
} finally {
748+
process.env.NODE_ENV = originalNodeEnv;
749+
}
708750
});
709751

710752
it('should always work with maintenance key', async () => {

src/GraphQL/ParseGraphQLServer.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,9 @@ class ParseGraphQLServer {
147147
// needed since we use graphql upload
148148
requestHeaders: ['X-Parse-Application-Id'],
149149
},
150-
introspection: this.config.graphQLPublicIntrospection,
150+
// We need always true introspection because apollo server have changing behavior based on the NODE_ENV variable
151+
// we delegate the introspection control to the IntrospectionControlPlugin
152+
introspection: true,
151153
plugins: [ApolloServerPluginCacheControlDisabled(), IntrospectionControlPlugin(this.config.graphQLPublicIntrospection)],
152154
schema,
153155
});

0 commit comments

Comments
 (0)