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

add internal helper for tada fragment unrolling (#285)

Changed files
+29 -1
.changeset
packages
graphqlsp
src
+5
.changeset/tough-squids-worry.md
···
···
+
---
+
'@0no-co/graphqlsp': patch
+
---
+
+
Add internal helper to unroll tada fragments
+1 -1
packages/graphqlsp/src/api.ts
···
export { getGraphQLDiagnostics } from './diagnostics';
export { init } from './ts';
-
export { findAllPersistedCallExpressions } from './ast';
export { getDocumentReferenceFromTypeQuery } from './persisted';
···
export { getGraphQLDiagnostics } from './diagnostics';
export { init } from './ts';
+
export { findAllPersistedCallExpressions, unrollTadaFragments } from './ast';
export { getDocumentReferenceFromTypeQuery } from './persisted';
+23
packages/graphqlsp/src/ast/index.ts
···
return fragments;
}
export function findAllCallExpressions(
sourceFile: ts.SourceFile,
info: ts.server.PluginCreateInfo,
···
return fragments;
}
+
export function unrollTadaFragments(
+
fragmentsArray: ts.ArrayLiteralExpression,
+
wip: FragmentDefinitionNode[],
+
info: ts.server.PluginCreateInfo
+
): FragmentDefinitionNode[] {
+
fragmentsArray.elements.forEach(element => {
+
if (ts.isIdentifier(element)) {
+
wip.push(...unrollFragment(element, info));
+
} else if (ts.isPropertyAccessExpression(element)) {
+
let el = element;
+
while (ts.isPropertyAccessExpression(el.expression)) {
+
el = el.expression;
+
}
+
+
if (ts.isIdentifier(el.name)) {
+
wip.push(...unrollFragment(el.name, info));
+
}
+
}
+
});
+
+
return wip;
+
}
+
export function findAllCallExpressions(
sourceFile: ts.SourceFile,
info: ts.server.PluginCreateInfo,