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

do not return 404 when using query params or trailing slash #2893

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/flat-tips-look.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'graphql-yoga': patch
---

do not return 404 when using query params for graphiql
18 changes: 18 additions & 0 deletions packages/graphql-yoga/src/plugins/use-graphiql.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,24 @@ describe('GraphiQL', () => {
expect(result).toMatch(/<title>Test GraphiQL<\/title>/)
})

it('renders graphiql when passing query params and trailing slash', async () => {
const yoga = createYoga({
graphiql: () => Promise.resolve({ title: 'Test GraphiQL' }),
})
const response = await yoga.fetch(
'http://localhost:3000/graphql?query=something+awesome',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add tests for trailing slash as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

closing this PR, not interested anymore

{
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),
Expand Down
2 changes: 1 addition & 1 deletion packages/graphql-yoga/src/plugins/use-graphiql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export function useGraphiQL<TServerContext extends Record<string, any>>(
async onRequest({ request, serverContext, fetchAPI, endResponse, url }) {
if (
shouldRenderGraphiQL(request) &&
(request.url.endsWith(config.graphqlEndpoint) ||
(request.url.split('?')[0].endsWith(config.graphqlEndpoint) ||
url.pathname === config.graphqlEndpoint ||
getUrlPattern(fetchAPI).test(url))
) {
Expand Down