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

fix: reference to incorrect node when computing schema name of persisted call (#333)

Co-authored-by: Jovi De Croock <decroockjovi@gmail.com>

Changed files
+13 -3
.changeset
packages
graphqlsp
+5
.changeset/lovely-phones-yell.md
···
+
---
+
"@0no-co/graphqlsp": patch
+
---
+
+
Fix schema derivation when using `graphql.persisted`, we used the wrong expression in the ast
+7 -2
packages/graphqlsp/src/ast/checks.ts
···
/** Retrieves the `__name` branded tag from gql.tada `graphql()` or `graphql.persisted()` calls */
export const getSchemaName = (
node: ts.CallExpression,
-
typeChecker: ts.TypeChecker | undefined
+
typeChecker: ts.TypeChecker | undefined,
+
isTadaPersistedCall = false
): string | null => {
if (!typeChecker) return null;
-
const type = typeChecker.getTypeAtLocation(node.expression);
+
const type = typeChecker.getTypeAtLocation(
+
// When calling `graphql.persisted`, we need to access the `graphql` part of
+
// the expression; `node.expression` is the `.persisted` part
+
isTadaPersistedCall ? node.getChildAt(0).getChildAt(0) : node.expression
+
);
if (type) {
const brandTypeSymbol = type.getProperty('__name');
if (brandTypeSymbol) {
+1 -1
packages/graphqlsp/src/ast/index.ts
···
if (!checks.isTadaPersistedCall(node, typeChecker)) {
return;
} else if (info) {
-
const name = checks.getSchemaName(node, typeChecker);
+
const name = checks.getSchemaName(node, typeChecker, true);
result.push({ node, schema: name });
} else {
result.push(node);