Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crash when when editing a file that doesn't belong to a project #3413

Merged
merged 1 commit into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@

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;

Check warning on line 134 in packages/graphql-language-service-server/src/GraphQLCache.ts

View check run for this annotation

Codecov / codecov/patch

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

Added line #L134 was not covered by tests
}
};

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