Skip to content

Commit d22f611

Browse files
committed
gently trap graphql parse errors in the LS and LSP
I introduced these accidentally and they have caused a lot of issues!
1 parent ee77792 commit d22f611

File tree

3 files changed

+22
-11
lines changed

3 files changed

+22
-11
lines changed

.changeset/wise-birds-notice.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'graphql-language-service': patch
3+
'graphql-language-service-server': patch
4+
---
5+
6+
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!

packages/graphql-language-service-server/src/MessageProcessor.ts

+7-6
Original file line numberDiff line numberDiff line change
@@ -690,12 +690,13 @@ export class MessageProcessor {
690690
}
691691

692692
const inlineFragments: string[] = [];
693-
694-
visit(parse(query), {
695-
FragmentDefinition: (node: FragmentDefinitionNode) => {
696-
inlineFragments.push(node.name.value);
697-
},
698-
});
693+
try {
694+
visit(parse(query), {
695+
FragmentDefinition: (node: FragmentDefinitionNode) => {
696+
inlineFragments.push(node.name.value);
697+
},
698+
});
699+
} catch {}
699700

700701
const formatted = result
701702
? result.definitions.map(res => {

packages/graphql-language-service/src/interface/getAutocompleteSuggestions.ts

+9-5
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,15 @@ export const SuggestionCommand = {
7979
const collectFragmentDefs = (op: string | undefined) => {
8080
const externalFragments: FragmentDefinitionNode[] = [];
8181
if (op) {
82-
visit(parse(op), {
83-
FragmentDefinition(def) {
84-
externalFragments.push(def);
85-
},
86-
});
82+
try {
83+
visit(parse(op), {
84+
FragmentDefinition(def) {
85+
externalFragments.push(def);
86+
},
87+
});
88+
} catch {
89+
return [];
90+
}
8791
}
8892
return externalFragments;
8993
};

0 commit comments

Comments
 (0)