Skip to content

Commit

Permalink
Fix crash when when editing a file that doesn't belong to a project
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
BPScott authored and acao committed Sep 26, 2023
1 parent 9e421ad commit 530ef47
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/slimy-needles-taste.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'graphql-language-service-server': patch
---

Fix crash when editing a file that does not belong to a project
5 changes: 2 additions & 3 deletions packages/graphql-language-service-server/src/GraphQLCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,15 +124,14 @@ export class GraphQLCache implements GraphQLCacheInterface {

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

getProjectForFile = (uri: string): GraphQLProjectConfig => {
getProjectForFile = (uri: string): GraphQLProjectConfig | void => {
try {
return this._graphQLConfig.getProjectForFile(URI.parse(uri).fsPath);
} catch (err) {
this._logger.error(
`there was an error loading the project config for this file ${err}`,
);
// @ts-expect-error
return null;
return;
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,9 @@ export class MessageProcessor {
await this._updateObjectTypeDefinition(uri, contents);

const project = this._graphQLCache.getProjectForFile(uri);
await this._updateSchemaIfChanged(project, uri);
if (project) {
await this._updateSchemaIfChanged(project, uri);
}

let diagnostics: Diagnostic[] = [];

Expand Down

0 comments on commit 530ef47

Please sign in to comment.