Skip to content

Commit

Permalink
add internal helper for tada fragment unrolling (#285)
Browse files Browse the repository at this point in the history
  • Loading branch information
JoviDeCroock authored Apr 5, 2024
1 parent 6a53946 commit 5e293e3
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/tough-squids-worry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@0no-co/graphqlsp': patch
---

Add internal helper to unroll tada fragments
2 changes: 1 addition & 1 deletion packages/graphqlsp/src/api.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export { getGraphQLDiagnostics } from './diagnostics';
export { init } from './ts';
export { findAllPersistedCallExpressions } from './ast';
export { findAllPersistedCallExpressions, unrollTadaFragments } from './ast';
export { getDocumentReferenceFromTypeQuery } from './persisted';
23 changes: 23 additions & 0 deletions packages/graphqlsp/src/ast/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,29 @@ function unrollFragment(
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,
Expand Down

0 comments on commit 5e293e3

Please sign in to comment.