diff --git a/packages/graphql-language-service-server/src/GraphQLCache.ts b/packages/graphql-language-service-server/src/GraphQLCache.ts index fcc5a3fc297..4480b029799 100644 --- a/packages/graphql-language-service-server/src/GraphQLCache.ts +++ b/packages/graphql-language-service-server/src/GraphQLCache.ts @@ -671,7 +671,7 @@ export class GraphQLCache implements GraphQLCacheInterface { return schema; }; - _invalidateSchemaCacheForProject(projectConfig: GraphQLProjectConfig) { + invalidateSchemaCacheForProject(projectConfig: GraphQLProjectConfig) { const schemaKey = this._getSchemaCacheKeyForProject( projectConfig, ) as string; diff --git a/packages/graphql-language-service-server/src/MessageProcessor.ts b/packages/graphql-language-service-server/src/MessageProcessor.ts index 4b52a6f40b4..80e1cb4456b 100644 --- a/packages/graphql-language-service-server/src/MessageProcessor.ts +++ b/packages/graphql-language-service-server/src/MessageProcessor.ts @@ -665,6 +665,8 @@ export class MessageProcessor { await this._updateObjectTypeDefinition(uri, contents); const project = this._graphQLCache.getProjectForFile(uri); + await this._updateSchemaIfChanged(project, uri); + let diagnostics: Diagnostic[] = []; if ( @@ -1138,6 +1140,18 @@ export class MessageProcessor { await this._graphQLCache.updateFragmentDefinition(rootDir, uri, contents); } + async _updateSchemaIfChanged( + project: GraphQLProjectConfig, + uri: Uri, + ): Promise { + const { dirpath, schema } = project; + const schemaFilePath = path.resolve(dirpath, schema as string); + const uriFilePath = URI.parse(uri).fsPath; + if (uriFilePath === schemaFilePath) { + await this._graphQLCache.invalidateSchemaCacheForProject(project); + } + } + async _updateObjectTypeDefinition( uri: Uri, contents: CachedContent[],