From 7d51c87553c5233d31ef9507920fcda6624390e8 Mon Sep 17 00:00:00 2001 From: Phil Pluckthun Date: Tue, 30 Jul 2024 13:37:53 +0100 Subject: [PATCH] Bail out of `unrollFragment` infinite loop --- packages/graphqlsp/src/ast/index.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/packages/graphqlsp/src/ast/index.ts b/packages/graphqlsp/src/ast/index.ts index a3e17e2..1a6377e 100644 --- a/packages/graphqlsp/src/ast/index.ts +++ b/packages/graphqlsp/src/ast/index.ts @@ -90,6 +90,13 @@ function unrollFragment( // If we found another identifier, we repeat trying to find the original // fragment definition if (ts.isIdentifier(found)) { + // NOTE: A gotcha of `getDefinitionAtPosition` is that when resolution fails, it points + // back at the original identifier (e.g. if its of the internal type `error`). + if (found === element) { + // TODO: Instead of bailing out here, we should be able to issue a diagnostic here + // that tells the user that resolution of a fragment has failed. + return fragments; + } return unrollFragment(found, info, typeChecker); }