Skip to content

Commit 75ccd72

Browse files
A-N-uraagacao
authored andcommitted
fix: LSP server crashing in case of error in schema
- Added try-catch block around handleWatchedFilesChangedNotification handler to prevent server crash on schema update.
1 parent 6674b7b commit 75ccd72

File tree

2 files changed

+44
-34
lines changed

2 files changed

+44
-34
lines changed

.changeset/lovely-steaks-knock.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'graphql-language-service-server': patch
3+
---
4+
5+
Fixed crashing of LSP server on saving a schema with errors

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

+39-34
Original file line numberDiff line numberDiff line change
@@ -664,42 +664,47 @@ export class MessageProcessor {
664664
await this._updateFragmentDefinition(uri, contents);
665665
await this._updateObjectTypeDefinition(uri, contents);
666666

667-
const project = this._graphQLCache.getProjectForFile(uri);
668-
if (project) {
669-
await this._updateSchemaIfChanged(project, uri);
670-
}
667+
try {
668+
const project = this._graphQLCache.getProjectForFile(uri);
669+
if (project) {
670+
await this._updateSchemaIfChanged(project, uri);
671+
}
671672

672-
let diagnostics: Diagnostic[] = [];
673-
674-
if (
675-
project?.extensions?.languageService?.enableValidation !== false
676-
) {
677-
diagnostics = (
678-
await Promise.all(
679-
contents.map(async ({ query, range }) => {
680-
const results = await this._languageService.getDiagnostics(
681-
query,
682-
uri,
683-
this._isRelayCompatMode(query),
684-
);
685-
if (results && results.length > 0) {
686-
return processDiagnosticsMessage(results, query, range);
687-
}
688-
return [];
689-
}),
690-
)
691-
).reduce((left, right) => left.concat(right), diagnostics);
692-
}
673+
let diagnostics: Diagnostic[] = [];
674+
675+
if (
676+
project?.extensions?.languageService?.enableValidation !== false
677+
) {
678+
diagnostics = (
679+
await Promise.all(
680+
contents.map(async ({ query, range }) => {
681+
const results = await this._languageService.getDiagnostics(
682+
query,
683+
uri,
684+
this._isRelayCompatMode(query),
685+
);
686+
if (results && results.length > 0) {
687+
return processDiagnosticsMessage(results, query, range);
688+
}
689+
return [];
690+
}),
691+
)
692+
).reduce((left, right) => left.concat(right), diagnostics);
693+
}
693694

694-
this._logger.log(
695-
JSON.stringify({
696-
type: 'usage',
697-
messageType: 'workspace/didChangeWatchedFiles',
698-
projectName: project?.name,
699-
fileName: uri,
700-
}),
701-
);
702-
return { uri, diagnostics };
695+
this._logger.log(
696+
JSON.stringify({
697+
type: 'usage',
698+
messageType: 'workspace/didChangeWatchedFiles',
699+
projectName: project?.name,
700+
fileName: uri,
701+
}),
702+
);
703+
return { uri, diagnostics };
704+
} catch (err) {
705+
this._handleConfigError({ err, uri });
706+
return { uri, diagnostics: [] };
707+
}
703708
}
704709
if (change.type === FileChangeTypeKind.Deleted) {
705710
await this._graphQLCache.updateFragmentDefinitionCache(

0 commit comments

Comments
 (0)