From 6222e5d26dc4a6847896814b5e789c25f445bc13 Mon Sep 17 00:00:00 2001 From: David Thyresson Date: Wed, 30 Aug 2023 19:55:56 -0400 Subject: [PATCH 1/3] Fix GraphiQL and Introspection config and adds tests --- .../__snapshots__/graphiql.test copy.ts.snap | 66 ++++++++++ .../src/__tests__/graphiql.test.ts | 122 ++++++++++++++++++ .../src/__tests__/introspection.test.ts | 105 +++++++++++++++ .../graphql-server/src/createGraphQLYoga.ts | 37 ++---- packages/graphql-server/src/graphiql.ts | 40 ++++++ packages/graphql-server/src/introspection.ts | 21 +++ packages/graphql-server/src/types.ts | 5 + 7 files changed, 370 insertions(+), 26 deletions(-) create mode 100644 packages/graphql-server/src/__tests__/__snapshots__/graphiql.test copy.ts.snap create mode 100644 packages/graphql-server/src/__tests__/graphiql.test.ts create mode 100644 packages/graphql-server/src/__tests__/introspection.test.ts create mode 100644 packages/graphql-server/src/graphiql.ts create mode 100644 packages/graphql-server/src/introspection.ts diff --git a/packages/graphql-server/src/__tests__/__snapshots__/graphiql.test copy.ts.snap b/packages/graphql-server/src/__tests__/__snapshots__/graphiql.test copy.ts.snap new file mode 100644 index 000000000000..f4ab15b77eaf --- /dev/null +++ b/packages/graphql-server/src/__tests__/__snapshots__/graphiql.test copy.ts.snap @@ -0,0 +1,66 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`configureGraphiQLPlayground when in development should configure the GraphiQL Playground when allowGraphiQL is not provided 1`] = ` +{ + "defaultQuery": "query Redwood { + redwood { + version + } + }", + "headerEditorEnabled": true, + "headers": undefined, + "title": "Redwood GraphQL Playground", +} +`; + +exports[`configureGraphiQLPlayground when in development should configure the GraphiQL Playground when allowGraphiQL is null 1`] = ` +{ + "defaultQuery": "query Redwood { + redwood { + version + } + }", + "headerEditorEnabled": true, + "headers": undefined, + "title": "Redwood GraphQL Playground", +} +`; + +exports[`configureGraphiQLPlayground when in development should configure the GraphiQL Playground when allowGraphiQL is true 1`] = ` +{ + "defaultQuery": "query Redwood { + redwood { + version + } + }", + "headerEditorEnabled": true, + "headers": undefined, + "title": "Redwood GraphQL Playground", +} +`; + +exports[`configureGraphiQLPlayground when in development should configure the GraphiQL Playground when allowGraphiQL is undefined 1`] = ` +{ + "defaultQuery": "query Redwood { + redwood { + version + } + }", + "headerEditorEnabled": true, + "headers": undefined, + "title": "Redwood GraphQL Playground", +} +`; + +exports[`configureGraphiQLPlayground when not in development environment should configure the GraphiQL Playground when allowGraphiQL is true 1`] = ` +{ + "defaultQuery": "query Redwood { + redwood { + version + } + }", + "headerEditorEnabled": true, + "headers": undefined, + "title": "Redwood GraphQL Playground", +} +`; diff --git a/packages/graphql-server/src/__tests__/graphiql.test.ts b/packages/graphql-server/src/__tests__/graphiql.test.ts new file mode 100644 index 000000000000..57009c76d073 --- /dev/null +++ b/packages/graphql-server/src/__tests__/graphiql.test.ts @@ -0,0 +1,122 @@ +import { configureGraphiQLPlayground } from '../graphiql' + +describe('configureGraphiQLPlayground', () => { + describe('when not in development environment', () => { + const curNodeEnv = process.env.NODE_ENV + + beforeAll(() => { + process.env.NODE_ENV = 'not-development' + }) + + afterAll(() => { + process.env.NODE_ENV = curNodeEnv + expect(process.env.NODE_ENV).toBe('test') + }) + + it('should configure the GraphiQL Playground when allowGraphiQL is true', () => { + const result = configureGraphiQLPlayground({ + allowGraphiQL: true, + generateGraphiQLHeader: jest.fn(), + }) + + expect(result).not.toBe(false) + expect(result).toMatchSnapshot() + }) + + it('should return false when allowGraphiQL is false', () => { + const result = configureGraphiQLPlayground({ + allowGraphiQL: false, + generateGraphiQLHeader: jest.fn(), + }) + + expect(result).toBe(false) + }) + + it('should return false when allowGraphiQL is not provided', () => { + const result = configureGraphiQLPlayground({ + generateGraphiQLHeader: jest.fn(), + }) + + expect(result).toBe(false) + }) + + it('should return false when allowGraphiQL is undefined', () => { + const result = configureGraphiQLPlayground({ + allowGraphiQL: undefined, + generateGraphiQLHeader: jest.fn(), + }) + + expect(result).toBe(false) + }) + + it('should return false when allowGraphiQL is null', () => { + const result = configureGraphiQLPlayground({ + allowGraphiQL: null, + generateGraphiQLHeader: jest.fn(), + }) + + expect(result).toBe(false) + }) + }) + + describe('when in development', () => { + const curNodeEnv = process.env.NODE_ENV + + beforeAll(() => { + process.env.NODE_ENV = 'development' + }) + + afterAll(() => { + process.env.NODE_ENV = curNodeEnv + expect(process.env.NODE_ENV).toBe('test') + }) + + it('should configure the GraphiQL Playground when allowGraphiQL is true', () => { + const result = configureGraphiQLPlayground({ + allowGraphiQL: true, + generateGraphiQLHeader: jest.fn(), + }) + + expect(result).not.toBe(false) + expect(result).toMatchSnapshot() + }) + + it('should configure the GraphiQL Playground when allowGraphiQL is false', () => { + const result = configureGraphiQLPlayground({ + allowGraphiQL: false, + generateGraphiQLHeader: jest.fn(), + }) + + expect(result).toBe(false) + }) + + it('should configure the GraphiQL Playground when allowGraphiQL is not provided', () => { + const result = configureGraphiQLPlayground({ + generateGraphiQLHeader: jest.fn(), + }) + + expect(result).not.toBe(false) + expect(result).toMatchSnapshot() + }) + + it('should configure the GraphiQL Playground when allowGraphiQL is undefined', () => { + const result = configureGraphiQLPlayground({ + allowGraphiQL: undefined, + generateGraphiQLHeader: jest.fn(), + }) + + expect(result).not.toBe(false) + expect(result).toMatchSnapshot() + }) + + it('should configure the GraphiQL Playground when allowGraphiQL is null', () => { + const result = configureGraphiQLPlayground({ + allowGraphiQL: null, + generateGraphiQLHeader: jest.fn(), + }) + + expect(result).not.toBe(false) + expect(result).toMatchSnapshot() + }) + }) +}) diff --git a/packages/graphql-server/src/__tests__/introspection.test.ts b/packages/graphql-server/src/__tests__/introspection.test.ts new file mode 100644 index 000000000000..b91cb67c4c8d --- /dev/null +++ b/packages/graphql-server/src/__tests__/introspection.test.ts @@ -0,0 +1,105 @@ +import { configureGraphQLIntrospection } from '../introspection' + +describe('configureGraphQLIntrospection', () => { + describe('when not in development environment', () => { + const curNodeEnv = process.env.NODE_ENV + + beforeAll(() => { + process.env.NODE_ENV = 'not-development' + }) + + afterAll(() => { + process.env.NODE_ENV = curNodeEnv + expect(process.env.NODE_ENV).toBe('test') + }) + + it('should not disable GraphQL Introspection when allowIntrospection is true', () => { + const { disableIntrospection } = configureGraphQLIntrospection({ + allowIntrospection: true, + }) + + expect(disableIntrospection).toBe(false) + }) + + it('should disable GraphQL Introspection when allowIntrospection is false', () => { + const { disableIntrospection } = configureGraphQLIntrospection({ + allowIntrospection: false, + }) + + expect(disableIntrospection).toBe(true) + }) + + it('should disable GraphQL Introspection when allowIntrospection is not provided', () => { + const { disableIntrospection } = configureGraphQLIntrospection({}) + + expect(disableIntrospection).toBe(true) + }) + + it('should disable GraphQL Introspection when allowIntrospection is undefined', () => { + const { disableIntrospection } = configureGraphQLIntrospection({ + allowIntrospection: undefined, + }) + + expect(disableIntrospection).toBe(true) + }) + + it('should disable GraphQL Introspection when allowIntrospection is null', () => { + const { disableIntrospection } = configureGraphQLIntrospection({ + allowIntrospection: null, + }) + + expect(disableIntrospection).toBe(true) + }) + }) + + describe('when in development', () => { + const curNodeEnv = process.env.NODE_ENV + + beforeAll(() => { + process.env.NODE_ENV = 'development' + }) + + afterAll(() => { + process.env.NODE_ENV = curNodeEnv + expect(process.env.NODE_ENV).toBe('test') + }) + + it('should not disable GraphQL Introspection when allowIntrospection is true', () => { + const { disableIntrospection } = configureGraphQLIntrospection({ + allowIntrospection: true, + }) + + expect(disableIntrospection).toBe(false) + }) + + it('should disable GraphQL Introspection when allowIntrospection is false', () => { + const { disableIntrospection } = configureGraphQLIntrospection({ + allowIntrospection: false, + }) + + expect(disableIntrospection).toBe(true) + }) + + it('should not disable GraphQL Introspection when allowIntrospection is not provided', () => { + const { disableIntrospection } = configureGraphQLIntrospection({}) + + expect(disableIntrospection).toBe(false) + }) + + it('should not disable GraphQL Introspection when allowIntrospection is undefined', () => { + const { disableIntrospection } = configureGraphQLIntrospection({ + allowIntrospection: undefined, + }) + + expect(disableIntrospection).toBe(false) + }) + + it('should not disable GraphQL Introspection when allowIntrospection is null', () => { + const { disableIntrospection } = configureGraphQLIntrospection({ + allowIntrospection: null, + }) + + expect(disableIntrospection).toBe(false) + }) + }) +}) diff --git a/packages/graphql-server/src/createGraphQLYoga.ts b/packages/graphql-server/src/createGraphQLYoga.ts index 4e838613d31f..d6f64b8b943c 100644 --- a/packages/graphql-server/src/createGraphQLYoga.ts +++ b/packages/graphql-server/src/createGraphQLYoga.ts @@ -6,6 +6,8 @@ import { Plugin, useReadinessCheck, createYoga } from 'graphql-yoga' import { mapRwCorsOptionsToYoga } from './cors' import { makeDirectivesForPlugin } from './directives/makeDirectives' +import { configureGraphiQLPlayground } from './graphiql' +import { configureGraphQLIntrospection } from './introspection' import { makeMergedSchema } from './makeMergedSchema' import { useArmor, @@ -52,6 +54,8 @@ export const createGraphQLYoga = ({ let redwoodDirectivePlugins = [] as Plugin[] const logger = loggerConfig.logger + const isDevEnv = process.env.NODE_ENV === 'development' + try { // @NOTE: Directives are optional const projectDirectives = makeDirectivesForPlugin(directives) @@ -94,31 +98,9 @@ export const createGraphQLYoga = ({ // so the order here matters const plugins: Array> = [] - const isDevEnv = process.env.NODE_ENV === 'development' - const disableIntrospection = - (allowIntrospection === null && !isDevEnv) || allowIntrospection === false - const disableGraphQL = - (allowGraphiQL === null && !isDevEnv) || allowGraphiQL === false - - const defaultQuery = `query Redwood { - redwood { - version - } - }` - - // TODO: Once Studio is not experimental, can remove these generateGraphiQLHeaders - const authHeader = `{"x-auth-comment": "See documentation: https://redwoodjs.com/docs/cli-commands#setup-graphiql-headers on how to auto generate auth headers"}` - - const graphiql = !disableGraphQL - ? { - title: 'Redwood GraphQL Playground', - headers: generateGraphiQLHeader - ? generateGraphiQLHeader() - : authHeader, - defaultQuery, - headerEditorEnabled: true, - } - : false + const { disableIntrospection } = configureGraphQLIntrospection({ + allowIntrospection, + }) if (disableIntrospection) { plugins.push(useDisableIntrospection()) @@ -208,7 +190,10 @@ export const createGraphQLYoga = ({ logging: logger, healthCheckEndpoint: graphiQLEndpoint + '/health', graphqlEndpoint: graphiQLEndpoint, - graphiql, + graphiql: configureGraphiQLPlayground({ + allowGraphiQL, + generateGraphiQLHeader, + }), cors: (request: Request) => { const requestOrigin = request.headers.get('origin') return mapRwCorsOptionsToYoga(cors, requestOrigin) diff --git a/packages/graphql-server/src/graphiql.ts b/packages/graphql-server/src/graphiql.ts new file mode 100644 index 000000000000..d42cd57ec8e8 --- /dev/null +++ b/packages/graphql-server/src/graphiql.ts @@ -0,0 +1,40 @@ +import type { GraphiQLOptions } from './types' +// import { isDevEnv } from './util' + +const DEFAULT_QUERY = `query Redwood { + redwood { + version + } + }` + +// TODO: Once Studio is not experimental, can remove these generateGraphiQLHeaders +const AUTH_HEADER = `{"x-auth-comment": "See documentation: https://redwoodjs.com/docs/cli-commands#setup-graphiql-headers on how to auto generate auth headers"}` + +export const configureGraphiQLPlayground = ({ + allowGraphiQL, + generateGraphiQLHeader, +}: GraphiQLOptions) => { + const isDevEnv = process.env.NODE_ENV === 'development' + + const disableGraphQL = + isDevEnv && (allowGraphiQL === undefined || allowGraphiQL === null) + ? false + : !allowGraphiQL + + console.log('isDevEnv', isDevEnv) + + console.log('allowGraphiQL', allowGraphiQL) + + console.log('disableGraphQL', disableGraphQL) + + return !disableGraphQL + ? { + title: 'Redwood GraphQL Playground', + headers: generateGraphiQLHeader + ? generateGraphiQLHeader() + : AUTH_HEADER, + defaultQuery: DEFAULT_QUERY, + headerEditorEnabled: true, + } + : false +} diff --git a/packages/graphql-server/src/introspection.ts b/packages/graphql-server/src/introspection.ts new file mode 100644 index 000000000000..54463947c3e8 --- /dev/null +++ b/packages/graphql-server/src/introspection.ts @@ -0,0 +1,21 @@ +import type { GraphQLYogaOptions } from './types' + +export const configureGraphQLIntrospection = ({ + allowIntrospection, +}: { + allowIntrospection: GraphQLYogaOptions['allowIntrospection'] +}) => { + const isDevEnv = process.env.NODE_ENV === 'development' + + console.log('isDevEnv', isDevEnv) + console.log('allowIntrospection', allowIntrospection) + const disableIntrospection = + isDevEnv && + (allowIntrospection === undefined || allowIntrospection === null) + ? false + : !allowIntrospection // ? + + return { + disableIntrospection, + } +} diff --git a/packages/graphql-server/src/types.ts b/packages/graphql-server/src/types.ts index 546fd8f55a70..003e38fe1289 100644 --- a/packages/graphql-server/src/types.ts +++ b/packages/graphql-server/src/types.ts @@ -244,3 +244,8 @@ export type GraphQLYogaOptions = { * Note: RedwoodRealtime is not supported */ export type GraphQLHandlerOptions = Omit + +export type GraphiQLOptions = Pick< + GraphQLYogaOptions, + 'allowGraphiQL' | 'generateGraphiQLHeader' +> From af5647d986926f981a4334cf48ad4896c8820b23 Mon Sep 17 00:00:00 2001 From: David Thyresson Date: Thu, 31 Aug 2023 10:03:43 -0400 Subject: [PATCH 2/3] Clean up debug logging --- .../{graphiql.test copy.ts.snap => graphiql.test.ts.snap} | 0 packages/graphql-server/src/graphiql.ts | 6 ------ packages/graphql-server/src/introspection.ts | 2 -- 3 files changed, 8 deletions(-) rename packages/graphql-server/src/__tests__/__snapshots__/{graphiql.test copy.ts.snap => graphiql.test.ts.snap} (100%) diff --git a/packages/graphql-server/src/__tests__/__snapshots__/graphiql.test copy.ts.snap b/packages/graphql-server/src/__tests__/__snapshots__/graphiql.test.ts.snap similarity index 100% rename from packages/graphql-server/src/__tests__/__snapshots__/graphiql.test copy.ts.snap rename to packages/graphql-server/src/__tests__/__snapshots__/graphiql.test.ts.snap diff --git a/packages/graphql-server/src/graphiql.ts b/packages/graphql-server/src/graphiql.ts index d42cd57ec8e8..ca893e4ebde0 100644 --- a/packages/graphql-server/src/graphiql.ts +++ b/packages/graphql-server/src/graphiql.ts @@ -21,12 +21,6 @@ export const configureGraphiQLPlayground = ({ ? false : !allowGraphiQL - console.log('isDevEnv', isDevEnv) - - console.log('allowGraphiQL', allowGraphiQL) - - console.log('disableGraphQL', disableGraphQL) - return !disableGraphQL ? { title: 'Redwood GraphQL Playground', diff --git a/packages/graphql-server/src/introspection.ts b/packages/graphql-server/src/introspection.ts index 54463947c3e8..eec429aaebc7 100644 --- a/packages/graphql-server/src/introspection.ts +++ b/packages/graphql-server/src/introspection.ts @@ -7,8 +7,6 @@ export const configureGraphQLIntrospection = ({ }) => { const isDevEnv = process.env.NODE_ENV === 'development' - console.log('isDevEnv', isDevEnv) - console.log('allowIntrospection', allowIntrospection) const disableIntrospection = isDevEnv && (allowIntrospection === undefined || allowIntrospection === null) From 39bc5e3fdafff12e2247213fd94d7d8c18d07ef3 Mon Sep 17 00:00:00 2001 From: Josh GM Walker <56300765+Josh-Walker-GM@users.noreply.github.com> Date: Thu, 31 Aug 2023 19:33:35 +0100 Subject: [PATCH 3/3] Minor refactoring and additional test cases --- .../__snapshots__/graphiql.test.ts.snap | 43 ++++++++++++------- .../src/__tests__/graphiql.test.ts | 15 +++++++ .../src/__tests__/introspection.test.ts | 6 ++- packages/graphql-server/src/graphiql.ts | 14 +++--- packages/graphql-server/src/introspection.ts | 7 +-- 5 files changed, 55 insertions(+), 30 deletions(-) diff --git a/packages/graphql-server/src/__tests__/__snapshots__/graphiql.test.ts.snap b/packages/graphql-server/src/__tests__/__snapshots__/graphiql.test.ts.snap index f4ab15b77eaf..407806882a52 100644 --- a/packages/graphql-server/src/__tests__/__snapshots__/graphiql.test.ts.snap +++ b/packages/graphql-server/src/__tests__/__snapshots__/graphiql.test.ts.snap @@ -3,10 +3,10 @@ exports[`configureGraphiQLPlayground when in development should configure the GraphiQL Playground when allowGraphiQL is not provided 1`] = ` { "defaultQuery": "query Redwood { - redwood { + redwood { version - } - }", + } +}", "headerEditorEnabled": true, "headers": undefined, "title": "Redwood GraphQL Playground", @@ -16,10 +16,10 @@ exports[`configureGraphiQLPlayground when in development should configure the Gr exports[`configureGraphiQLPlayground when in development should configure the GraphiQL Playground when allowGraphiQL is null 1`] = ` { "defaultQuery": "query Redwood { - redwood { + redwood { version - } - }", + } +}", "headerEditorEnabled": true, "headers": undefined, "title": "Redwood GraphQL Playground", @@ -29,10 +29,10 @@ exports[`configureGraphiQLPlayground when in development should configure the Gr exports[`configureGraphiQLPlayground when in development should configure the GraphiQL Playground when allowGraphiQL is true 1`] = ` { "defaultQuery": "query Redwood { - redwood { + redwood { version - } - }", + } +}", "headerEditorEnabled": true, "headers": undefined, "title": "Redwood GraphQL Playground", @@ -42,23 +42,36 @@ exports[`configureGraphiQLPlayground when in development should configure the Gr exports[`configureGraphiQLPlayground when in development should configure the GraphiQL Playground when allowGraphiQL is undefined 1`] = ` { "defaultQuery": "query Redwood { - redwood { + redwood { version - } - }", + } +}", "headerEditorEnabled": true, "headers": undefined, "title": "Redwood GraphQL Playground", } `; +exports[`configureGraphiQLPlayground when in development should configure the GraphiQL Playground when no config is provided 1`] = ` +{ + "defaultQuery": "query Redwood { + redwood { + version + } +}", + "headerEditorEnabled": true, + "headers": "{"x-auth-comment": "See documentation: https://redwoodjs.com/docs/cli-commands#setup-graphiql-headers on how to auto generate auth headers"}", + "title": "Redwood GraphQL Playground", +} +`; + exports[`configureGraphiQLPlayground when not in development environment should configure the GraphiQL Playground when allowGraphiQL is true 1`] = ` { "defaultQuery": "query Redwood { - redwood { + redwood { version - } - }", + } +}", "headerEditorEnabled": true, "headers": undefined, "title": "Redwood GraphQL Playground", diff --git a/packages/graphql-server/src/__tests__/graphiql.test.ts b/packages/graphql-server/src/__tests__/graphiql.test.ts index 57009c76d073..e3cc52ae6b67 100644 --- a/packages/graphql-server/src/__tests__/graphiql.test.ts +++ b/packages/graphql-server/src/__tests__/graphiql.test.ts @@ -13,6 +13,12 @@ describe('configureGraphiQLPlayground', () => { expect(process.env.NODE_ENV).toBe('test') }) + it('should return false when no config is provided', () => { + const result = configureGraphiQLPlayground({}) + + expect(result).toBe(false) + }) + it('should configure the GraphiQL Playground when allowGraphiQL is true', () => { const result = configureGraphiQLPlayground({ allowGraphiQL: true, @@ -51,6 +57,7 @@ describe('configureGraphiQLPlayground', () => { it('should return false when allowGraphiQL is null', () => { const result = configureGraphiQLPlayground({ + // @ts-expect-error - We don't explicitly allow null, but we will cover it in the tests anyway allowGraphiQL: null, generateGraphiQLHeader: jest.fn(), }) @@ -71,6 +78,13 @@ describe('configureGraphiQLPlayground', () => { expect(process.env.NODE_ENV).toBe('test') }) + it('should configure the GraphiQL Playground when no config is provided', () => { + const result = configureGraphiQLPlayground({}) + + expect(result).not.toBe(false) + expect(result).toMatchSnapshot() + }) + it('should configure the GraphiQL Playground when allowGraphiQL is true', () => { const result = configureGraphiQLPlayground({ allowGraphiQL: true, @@ -111,6 +125,7 @@ describe('configureGraphiQLPlayground', () => { it('should configure the GraphiQL Playground when allowGraphiQL is null', () => { const result = configureGraphiQLPlayground({ + // @ts-expect-error - We don't explicitly allow null, but we will cover it in the tests anyway allowGraphiQL: null, generateGraphiQLHeader: jest.fn(), }) diff --git a/packages/graphql-server/src/__tests__/introspection.test.ts b/packages/graphql-server/src/__tests__/introspection.test.ts index b91cb67c4c8d..25fb83604275 100644 --- a/packages/graphql-server/src/__tests__/introspection.test.ts +++ b/packages/graphql-server/src/__tests__/introspection.test.ts @@ -29,7 +29,7 @@ describe('configureGraphQLIntrospection', () => { expect(disableIntrospection).toBe(true) }) - it('should disable GraphQL Introspection when allowIntrospection is not provided', () => { + it('should disable GraphQL Introspection when allowIntrospection is not provided', () => { const { disableIntrospection } = configureGraphQLIntrospection({}) expect(disableIntrospection).toBe(true) @@ -43,8 +43,9 @@ describe('configureGraphQLIntrospection', () => { expect(disableIntrospection).toBe(true) }) - it('should disable GraphQL Introspection when allowIntrospection is null', () => { + it('should disable GraphQL Introspection when allowIntrospection is null', () => { const { disableIntrospection } = configureGraphQLIntrospection({ + // @ts-expect-error - We don't explicitly allow null, but we will cover it in the tests anyway allowIntrospection: null, }) @@ -96,6 +97,7 @@ describe('configureGraphQLIntrospection', () => { it('should not disable GraphQL Introspection when allowIntrospection is null', () => { const { disableIntrospection } = configureGraphQLIntrospection({ + // @ts-expect-error - We don't explicitly allow null, but we will cover it in the tests anyway allowIntrospection: null, }) diff --git a/packages/graphql-server/src/graphiql.ts b/packages/graphql-server/src/graphiql.ts index ca893e4ebde0..c5784a76ba61 100644 --- a/packages/graphql-server/src/graphiql.ts +++ b/packages/graphql-server/src/graphiql.ts @@ -2,10 +2,10 @@ import type { GraphiQLOptions } from './types' // import { isDevEnv } from './util' const DEFAULT_QUERY = `query Redwood { - redwood { + redwood { version - } - }` + } +}` // TODO: Once Studio is not experimental, can remove these generateGraphiQLHeaders const AUTH_HEADER = `{"x-auth-comment": "See documentation: https://redwoodjs.com/docs/cli-commands#setup-graphiql-headers on how to auto generate auth headers"}` @@ -16,12 +16,10 @@ export const configureGraphiQLPlayground = ({ }: GraphiQLOptions) => { const isDevEnv = process.env.NODE_ENV === 'development' - const disableGraphQL = - isDevEnv && (allowGraphiQL === undefined || allowGraphiQL === null) - ? false - : !allowGraphiQL + const disableGraphiQL = + isDevEnv && (allowGraphiQL ?? true) ? false : !allowGraphiQL - return !disableGraphQL + return !disableGraphiQL ? { title: 'Redwood GraphQL Playground', headers: generateGraphiQLHeader diff --git a/packages/graphql-server/src/introspection.ts b/packages/graphql-server/src/introspection.ts index eec429aaebc7..37c24aa88508 100644 --- a/packages/graphql-server/src/introspection.ts +++ b/packages/graphql-server/src/introspection.ts @@ -3,15 +3,12 @@ import type { GraphQLYogaOptions } from './types' export const configureGraphQLIntrospection = ({ allowIntrospection, }: { - allowIntrospection: GraphQLYogaOptions['allowIntrospection'] + allowIntrospection?: GraphQLYogaOptions['allowIntrospection'] }) => { const isDevEnv = process.env.NODE_ENV === 'development' const disableIntrospection = - isDevEnv && - (allowIntrospection === undefined || allowIntrospection === null) - ? false - : !allowIntrospection // ? + isDevEnv && (allowIntrospection ?? true) ? false : !allowIntrospection return { disableIntrospection,