Skip to content

Commit

Permalink
fix(lsp): prevent crash with empty list of definitions (#271)
Browse files Browse the repository at this point in the history
  • Loading branch information
JoviDeCroock authored Mar 20, 2024
1 parent 8c79c98 commit 3c4586c
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/rotten-stingrays-kick.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@0no-co/graphqlsp': patch
---

Fix case where our fragments is an empty array
4 changes: 2 additions & 2 deletions packages/graphqlsp/src/ast/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ function unrollFragment(
element.getStart()
);

if (!definitions) return fragments;
if (!definitions || !definitions.length) return fragments;

const [fragment] = definitions;

Expand Down Expand Up @@ -159,7 +159,7 @@ export function getAllFragments(
fileName,
node.expression.getStart()
);
if (!definitions) return fragments;
if (!definitions || !definitions.length) return fragments;

if (node.arguments[1] && ts.isArrayLiteralExpression(node.arguments[1])) {
const arg2 = node.arguments[1] as ts.ArrayLiteralExpression;
Expand Down
2 changes: 1 addition & 1 deletion packages/graphqlsp/src/ast/resolve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export function resolveTemplate(
filename,
span.expression.getStart()
);
if (!definitions) return;
if (!definitions || !definitions.length) return;

const def = definitions[0];
const src = getSource(info, def.fileName);
Expand Down

0 comments on commit 3c4586c

Please sign in to comment.