Mirror: TypeScript LSP plugin that finds GraphQL documents in your code and provides diagnostics, auto-complete and hover-information.

fix(graphqlsp): Fix resolving fragments as assignments (#322)

Changed files
+15
.changeset
packages
graphqlsp
src
ast
+5
.changeset/fuzzy-donkeys-kneel.md
···
+
---
+
'@0no-co/graphqlsp': patch
+
---
+
+
Fix fragments not being resolved when they're assigned to a property on an arbitrary identifier as an identifier.
+10
packages/graphqlsp/src/ast/index.ts
···
let found = findNode(externalSource, fragment.textSpan.start);
if (!found) return fragments;
+
while (ts.isPropertyAccessExpression(found.parent)) found = found.parent;
+
if (
ts.isVariableDeclaration(found.parent) &&
found.parent.initializer &&
···
found = found.parent.initializer;
} else if (ts.isPropertyAssignment(found.parent)) {
found = found.parent.initializer;
+
} else if (ts.isBinaryExpression(found.parent)) {
+
found = found.parent.right;
+
}
+
+
// If we found another identifier, we repeat trying to find the original
+
// fragment definition
+
if (ts.isIdentifier(found)) {
+
return unrollFragment(found, info, typeChecker);
}
// Check whether we've got a `graphql()` or `gql()` call, by the