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

Configure Feed

Select the types of activity you want to include in your feed.

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

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

authored by

Fela Maslen
Jovi De Croock
and committed by
GitHub
be3ec668 31c96bcf

+13 -3
+5
.changeset/lovely-phones-yell.md
··· 1 + --- 2 + "@0no-co/graphqlsp": patch 3 + --- 4 + 5 + Fix schema derivation when using `graphql.persisted`, we used the wrong expression in the ast
+7 -2
packages/graphqlsp/src/ast/checks.ts
··· 93 93 /** Retrieves the `__name` branded tag from gql.tada `graphql()` or `graphql.persisted()` calls */ 94 94 export const getSchemaName = ( 95 95 node: ts.CallExpression, 96 - typeChecker: ts.TypeChecker | undefined 96 + typeChecker: ts.TypeChecker | undefined, 97 + isTadaPersistedCall = false 97 98 ): string | null => { 98 99 if (!typeChecker) return null; 99 - const type = typeChecker.getTypeAtLocation(node.expression); 100 + const type = typeChecker.getTypeAtLocation( 101 + // When calling `graphql.persisted`, we need to access the `graphql` part of 102 + // the expression; `node.expression` is the `.persisted` part 103 + isTadaPersistedCall ? node.getChildAt(0).getChildAt(0) : node.expression 104 + ); 100 105 if (type) { 101 106 const brandTypeSymbol = type.getProperty('__name'); 102 107 if (brandTypeSymbol) {
+1 -1
packages/graphqlsp/src/ast/index.ts
··· 215 215 if (!checks.isTadaPersistedCall(node, typeChecker)) { 216 216 return; 217 217 } else if (info) { 218 - const name = checks.getSchemaName(node, typeChecker); 218 + const name = checks.getSchemaName(node, typeChecker, true); 219 219 result.push({ node, schema: name }); 220 220 } else { 221 221 result.push(node);