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

fix(graphqlsp): Fix infinite loop conditions when resolving fragments #350

Merged
merged 4 commits into from
Aug 22, 2024

Conversation

kitten
Copy link
Member

@kitten kitten commented Aug 21, 2024

Resolve 0no-co/gql.tada#374

Summary

Two loops can occur when resolving fragments:

  • Loops between mutual fragments
  • Loops when resolving an identifier

The first one is mostly to prevent crashes, but is already invalid and will lead to invalid behaviour. This occurs when two references reference each other. If TypeScript happens to still be able to resolve this condition, then we'd infinitely jump between the two fragments. This is easily prevented by keeping a WeakSet of Identifiers.

The second condition — which is more common in valid code — happens in scenarios when resolving an identifier leads back to this same identifier. I'm not 100% sure when this happens, but it's easily prevented.

I separated the fragment resolution into two parts to make the issue stand out more as well.

Set of changes

  • Extract GraphQL Node resolution from unrollFragment
  • Prevent resolving the same identifier twice in a row
  • Prevent unrollFragment from recursing
  • Prevent unrollFragment from processing the same identifier twice

Copy link

changeset-bot bot commented Aug 21, 2024

🦋 Changeset detected

Latest commit: e17a80a

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

This PR includes changesets to release 1 package
Name Type
@0no-co/graphqlsp 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

@kitten kitten merged commit 1ef3b51 into main Aug 22, 2024
1 check passed
@kitten kitten deleted the fix/infinite-loop-and-recurse-unroll branch August 22, 2024 09:03
@github-actions github-actions bot mentioned this pull request Aug 22, 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.

RangeError: Maximum call stack size exceeded running bun x gql.tada turbo
2 participants