Skip to content

Commit

Permalink
fix: reference to incorrect node when computing schema name of persis…
Browse files Browse the repository at this point in the history
…ted call
  • Loading branch information
felamaslen committed Jun 11, 2024
1 parent 31c96bc commit 1fc8914
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
7 changes: 5 additions & 2 deletions packages/graphqlsp/src/ast/checks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,13 @@ export const isGraphQLTag = (
/** 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(
isTadaPersistedCall ? node.getChildAt(0).getChildAt(0) : node.expression
);
if (type) {
const brandTypeSymbol = type.getProperty('__name');
if (brandTypeSymbol) {
Expand Down
2 changes: 1 addition & 1 deletion packages/graphqlsp/src/ast/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ export function findAllPersistedCallExpressions(
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);
Expand Down

0 comments on commit 1fc8914

Please sign in to comment.