Skip to content

Commit

Permalink
gently trap graphql parse errors in the LS and LSP
Browse files Browse the repository at this point in the history
I introduced these accidentally and they have caused a lot of issues!
  • Loading branch information
acao committed Apr 26, 2022
1 parent ee77792 commit d22f611
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 11 deletions.
6 changes: 6 additions & 0 deletions .changeset/wise-birds-notice.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'graphql-language-service': patch
'graphql-language-service-server': patch
---

Trap all graphql parsing exceptions from (relatively) newly added logic. This should clear up bugs that have been plauging users for two years now, sorry!
13 changes: 7 additions & 6 deletions packages/graphql-language-service-server/src/MessageProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -690,12 +690,13 @@ export class MessageProcessor {
}

const inlineFragments: string[] = [];

visit(parse(query), {
FragmentDefinition: (node: FragmentDefinitionNode) => {
inlineFragments.push(node.name.value);
},
});
try {
visit(parse(query), {
FragmentDefinition: (node: FragmentDefinitionNode) => {
inlineFragments.push(node.name.value);
},
});
} catch {}

const formatted = result
? result.definitions.map(res => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,15 @@ export const SuggestionCommand = {
const collectFragmentDefs = (op: string | undefined) => {
const externalFragments: FragmentDefinitionNode[] = [];
if (op) {
visit(parse(op), {
FragmentDefinition(def) {
externalFragments.push(def);
},
});
try {
visit(parse(op), {
FragmentDefinition(def) {
externalFragments.push(def);
},
});
} catch {
return [];
}
}
return externalFragments;
};
Expand Down

0 comments on commit d22f611

Please sign in to comment.