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: Export `findAllCallExpressions` and restore backwards-compat for `findAllPersistedCallExpressions` (#308)

authored by

Phil Pluckthun and committed by
GitHub
474ca19d 8e09c9b3

+31 -7
+5
.changeset/spicy-garlics-drum.md
··· 1 + --- 2 + '@0no-co/graphqlsp': minor 3 + --- 4 + 5 + Expose `findAllCallExpressions` on `@0no-co/graphqlsp/api`
+7 -1
packages/graphqlsp/src/api.ts
··· 1 1 export { getGraphQLDiagnostics } from './diagnostics'; 2 2 export { init } from './ts'; 3 - export { findAllPersistedCallExpressions, unrollTadaFragments } from './ast'; 3 + 4 + export { 5 + findAllPersistedCallExpressions, 6 + findAllCallExpressions, 7 + unrollTadaFragments, 8 + } from './ast'; 9 + 4 10 export { 5 11 getDocumentReferenceFromTypeQuery, 6 12 getDocumentReferenceFromDocumentNode,
+19 -6
packages/graphqlsp/src/ast/index.ts
··· 207 207 } 208 208 209 209 export function findAllPersistedCallExpressions( 210 + sourceFile: ts.SourceFile 211 + ): Array<ts.CallExpression>; 212 + export function findAllPersistedCallExpressions( 210 213 sourceFile: ts.SourceFile, 211 214 info: ts.server.PluginCreateInfo 212 - ): Array<{ node: ts.CallExpression; schema: string | null }> { 213 - const result: Array<{ node: ts.CallExpression; schema: string | null }> = []; 214 - const typeChecker = info.languageService.getProgram()?.getTypeChecker(); 215 + ): Array<{ node: ts.CallExpression; schema: string | null }>; 216 + 217 + export function findAllPersistedCallExpressions( 218 + sourceFile: ts.SourceFile, 219 + info?: ts.server.PluginCreateInfo 220 + ) { 221 + const result: Array< 222 + ts.CallExpression | { node: ts.CallExpression; schema: string | null } 223 + > = []; 224 + const typeChecker = info?.languageService.getProgram()?.getTypeChecker(); 215 225 function find(node: ts.Node) { 216 226 if (node && ts.isCallExpression(node)) { 217 227 // This expression ideally for us looks like <template>.persisted ··· 222 232 const [template, method] = parts; 223 233 if (!templates.has(template) || method !== 'persisted') return; 224 234 225 - const name = getSchemaName(node, typeChecker); 226 - 227 - result.push({ node, schema: name }); 235 + if (info) { 236 + const name = getSchemaName(node, typeChecker); 237 + result.push({ node, schema: name }); 238 + } else { 239 + result.push(node); 240 + } 228 241 } else { 229 242 ts.forEachChild(node, find); 230 243 }