Skip to content

Commit 1d5d9a6

Browse files
authored
fix(graphqlsp): Fix resolving fragments as assignments (#322)
1 parent b6fab06 commit 1d5d9a6

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

.changeset/fuzzy-donkeys-kneel.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@0no-co/graphqlsp': patch
3+
---
4+
5+
Fix fragments not being resolved when they're assigned to a property on an arbitrary identifier as an identifier.

packages/graphqlsp/src/ast/index.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ function unrollFragment(
7070
let found = findNode(externalSource, fragment.textSpan.start);
7171
if (!found) return fragments;
7272

73+
while (ts.isPropertyAccessExpression(found.parent)) found = found.parent;
74+
7375
if (
7476
ts.isVariableDeclaration(found.parent) &&
7577
found.parent.initializer &&
@@ -78,6 +80,14 @@ function unrollFragment(
7880
found = found.parent.initializer;
7981
} else if (ts.isPropertyAssignment(found.parent)) {
8082
found = found.parent.initializer;
83+
} else if (ts.isBinaryExpression(found.parent)) {
84+
found = found.parent.right;
85+
}
86+
87+
// If we found another identifier, we repeat trying to find the original
88+
// fragment definition
89+
if (ts.isIdentifier(found)) {
90+
return unrollFragment(found, info, typeChecker);
8191
}
8292

8393
// Check whether we've got a `graphql()` or `gql()` call, by the

0 commit comments

Comments
 (0)