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

Conversation

nescalante
Copy link
Contributor

this PR fixes two errors:

  • when using graphiql and then writing a query, graphiql adds "?query=your+query" to the query params. When refreshing the page this is returning 404 since the "unhandled route" validation is not taking query params into account.
  • in the same line, the same validation is throwing 404 when using trailing slashes in the url

I added a test for these two cases and then fixed them

@changeset-bot
Copy link

changeset-bot bot commented Jun 27, 2023

🦋 Changeset detected

Latest commit: 7aba56b

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 10 packages
Name Type
graphql-yoga Patch
apollo-federation-gateway-with-yoga Patch
apollo-subgraph-with-yoga Patch
graphql-lambda Patch
cloudflare-advanced Patch
cloudflare Patch
functions Patch
hackernews Patch
nextjs-app Patch
hello-world-benchmark Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

n1ru4l
n1ru4l previously approved these changes Jun 27, 2023
@ardatan
Copy link
Collaborator

ardatan commented Jun 27, 2023

Let's hold this one. That "if" condition is important for the performance. Maybe the path needs to be normalized in whatwg-node instead

@n1ru4l n1ru4l self-requested a review June 27, 2023 10:36
@n1ru4l
Copy link
Collaborator

n1ru4l commented Jun 27, 2023

@nescalante What is the use-case of using a trailing slash for the graphql endpoint? Why would you want to use both /graphql and /graphql/?

In case you want to only use /graphql/, you could instead use the graphqlEndpoint option passed to createYoga, for specifying /graphql/ as your graphql endpoint.

@nescalante
Copy link
Contributor Author

nescalante commented Jun 27, 2023

@n1ru4l basically in general sites "ignore" the trailing slash so both https://github.com/dotansimha/graphql-yoga/ and github.com/dotansimha/graphql-yoga are valid urls. Express also supports both URL with trailing and without trailing slash.

@nescalante
Copy link
Contributor Author

@ardatan regarding performance, would you prefer this alternative without regexes?

@n1ru4l
Copy link
Collaborator

n1ru4l commented Jun 27, 2023

@nescalante Wouldn't that indicate duplicated routes, shouldn't a trailing slash instead return a 301 with the location without the trailing slash?

@n1ru4l n1ru4l dismissed their stale review June 27, 2023 16:53

i changed my mind

@nescalante
Copy link
Contributor Author

nescalante commented Jun 27, 2023

ok, two questions then:

  • what do you think about passing a custom validation for properties? so instead of having a fixed string for the graphqlEndpoint, a function that validates that the graphqlEndpoint is ok
  • would you be ok with separating the query parameters fix as a separate thing?

if you agree with approach 1, then I will be happy to discuss the right way to provide this option.

My main concern is that validations over URL are too strict, and I can't handle them. So I can't have graphql over two endpoints for example, or graphql in one endpoint, and graphiql in another one

@nescalante
Copy link
Contributor Author

😴

@n1ru4l n1ru4l requested a review from ardatan August 11, 2023 08:54
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

@Urigo
Copy link
Collaborator

Urigo commented Nov 30, 2023

Thank you @nescalante for the contribution and I'm very sorry we haven't got to review it in a timely manner...

We've now shipped this change thanks to another contribution from @antonio-iodice

We'll do better with swiftly reviewing changes from valuable contributors such as yourself
❤️

This was referenced May 7, 2024
This was referenced May 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants