Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[v3] Fixed graphiql ignoring options if GraphiQLOptionFactory returns Promise #2246

Merged
merged 1 commit into from
Dec 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/eighty-crabs-stare.md
@@ -0,0 +1,5 @@
---
'@graphql-yoga/common': patch
---

Fixed graphiql ignoring options if `GraphiQLOptionFactory` returns Promise
34 changes: 34 additions & 0 deletions packages/graphql-yoga/src/plugins/useGraphiQL.spec.ts
@@ -0,0 +1,34 @@
import { createYoga } from '../server'

describe('GraphiQL', () => {
describe('when received an option factory that returns Promise', () => {
it('should respect graphiql option', async () => {
const yoga = createYoga({
graphiql: () => Promise.resolve({ title: 'Test GraphiQL' }),
})
const response = await yoga.fetch('http://localhost:3000/graphql', {
method: 'GET',
headers: {
Accept: 'text/html',
},
})
expect(response.headers.get('content-type')).toEqual('text/html')
const result = await response.text()
expect(result).toMatch(/<title>Test GraphiQL<\/title>/)
})

it('returns error when graphiql is disabled', async () => {
const yoga = createYoga({
graphiql: () => Promise.resolve(false),
})
const response = await yoga.fetch('http://localhost:3000/graphql', {
method: 'GET',
headers: {
Accept: 'text/html',
},
})
expect(response.headers.get('content-type')).not.toEqual('text/html')
expect(response.status).toEqual(406)
})
})
})
2 changes: 1 addition & 1 deletion packages/graphql-yoga/src/plugins/useGraphiQL.ts
Expand Up @@ -107,7 +107,7 @@ export function useGraphiQL<TServerContext extends Record<string, any>>(
config.graphqlEndpoint === url.pathname
) {
logger.debug(`Rendering GraphiQL`)
const graphiqlOptions = graphiqlOptionsFactory(
const graphiqlOptions = await graphiqlOptionsFactory(
request,
serverContext as TServerContext,
)
Expand Down