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 (#333)

Co-authored-by: Jovi De Croock <decroockjovi@gmail.com>
  • Loading branch information
felamaslen and JoviDeCroock committed Jun 11, 2024
1 parent 31c96bc commit be3ec66
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/lovely-phones-yell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@0no-co/graphqlsp": patch
---

Fix schema derivation when using `graphql.persisted`, we used the wrong expression in the ast
9 changes: 7 additions & 2 deletions packages/graphqlsp/src/ast/checks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,15 @@ 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(
// 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) {
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 be3ec66

Please sign in to comment.