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(lsp): prevent crash with empty list of definitions (#271)

authored by

Jovi De Croock and committed by
GitHub
3c4586c2 8c79c98b

+8 -3
+5
.changeset/rotten-stingrays-kick.md
··· 1 + --- 2 + '@0no-co/graphqlsp': patch 3 + --- 4 + 5 + Fix case where our fragments is an empty array
+2 -2
packages/graphqlsp/src/ast/index.ts
··· 58 58 element.getStart() 59 59 ); 60 60 61 - if (!definitions) return fragments; 61 + if (!definitions || !definitions.length) return fragments; 62 62 63 63 const [fragment] = definitions; 64 64 ··· 159 159 fileName, 160 160 node.expression.getStart() 161 161 ); 162 - if (!definitions) return fragments; 162 + if (!definitions || !definitions.length) return fragments; 163 163 164 164 if (node.arguments[1] && ts.isArrayLiteralExpression(node.arguments[1])) { 165 165 const arg2 = node.arguments[1] as ts.ArrayLiteralExpression;
+1 -1
packages/graphqlsp/src/ast/resolve.ts
··· 38 38 filename, 39 39 span.expression.getStart() 40 40 ); 41 - if (!definitions) return; 41 + if (!definitions || !definitions.length) return; 42 42 43 43 const def = definitions[0]; 44 44 const src = getSource(info, def.fileName);