fix(graphqlsp): Fix infinite loop conditions when resolving fragments
Resolve https://github.com/0no-co/gql.tada/issues/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
unrollFragmentfrom recursing - Prevent
unrollFragmentfrom processing the same identifier twice
🦋 Changeset detected
Latest commit: e17a80a0e98cf41307e5f131f7e021a5375a6871
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