diff --git a/.changeset/slimy-needles-taste.md b/.changeset/slimy-needles-taste.md new file mode 100644 index 00000000000..7c6457818d2 --- /dev/null +++ b/.changeset/slimy-needles-taste.md @@ -0,0 +1,5 @@ +--- +'graphql-language-service-server': patch +--- + +Fix crash when editing a file that does not belong to a project diff --git a/packages/graphql-language-service-server/src/GraphQLCache.ts b/packages/graphql-language-service-server/src/GraphQLCache.ts index fcf578d42fd..7a3e0da2bdb 100644 --- a/packages/graphql-language-service-server/src/GraphQLCache.ts +++ b/packages/graphql-language-service-server/src/GraphQLCache.ts @@ -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; } }; diff --git a/packages/graphql-language-service-server/src/MessageProcessor.ts b/packages/graphql-language-service-server/src/MessageProcessor.ts index 007d78f862f..4772d8f1058 100644 --- a/packages/graphql-language-service-server/src/MessageProcessor.ts +++ b/packages/graphql-language-service-server/src/MessageProcessor.ts @@ -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[] = [];