GraphQLSP icon indicating copy to clipboard operation
GraphQLSP copied to clipboard

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

Open kitten opened this issue 1 year ago • 1 comments

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 unrollFragment from recursing
  • Prevent unrollFragment from processing the same identifier twice

kitten avatar Aug 21 '24 21:08 kitten

🦋 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

changeset-bot[bot] avatar Aug 21 '24 21:08 changeset-bot[bot]