Skip to content

Commit 530ef47

Browse files
BPScottacao
authored andcommitted
Fix crash when when editing a file that doesn't belong to a project
getProjectForFile may return void when there is no project for that file. Wrap the call to updateSchemaIfChanged with a check to ensure that a project is present.
1 parent 9e421ad commit 530ef47

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

.changeset/slimy-needles-taste.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'graphql-language-service-server': patch
3+
---
4+
5+
Fix crash when editing a file that does not belong to a project

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,15 +124,14 @@ export class GraphQLCache implements GraphQLCacheInterface {
124124

125125
getGraphQLConfig = (): GraphQLConfig => this._graphQLConfig;
126126

127-
getProjectForFile = (uri: string): GraphQLProjectConfig => {
127+
getProjectForFile = (uri: string): GraphQLProjectConfig | void => {
128128
try {
129129
return this._graphQLConfig.getProjectForFile(URI.parse(uri).fsPath);
130130
} catch (err) {
131131
this._logger.error(
132132
`there was an error loading the project config for this file ${err}`,
133133
);
134-
// @ts-expect-error
135-
return null;
134+
return;
136135
}
137136
};
138137

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -665,7 +665,9 @@ export class MessageProcessor {
665665
await this._updateObjectTypeDefinition(uri, contents);
666666

667667
const project = this._graphQLCache.getProjectForFile(uri);
668-
await this._updateSchemaIfChanged(project, uri);
668+
if (project) {
669+
await this._updateSchemaIfChanged(project, uri);
670+
}
669671

670672
let diagnostics: Diagnostic[] = [];
671673

0 commit comments

Comments
 (0)