Skip to content

Commit

Permalink
fix: Invalidate the schema when the file has been changed
Browse files Browse the repository at this point in the history
  • Loading branch information
simowe committed Jun 7, 2023
1 parent 134d210 commit 0aeebd7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -671,7 +671,7 @@ export class GraphQLCache implements GraphQLCacheInterface {
return schema;
};

_invalidateSchemaCacheForProject(projectConfig: GraphQLProjectConfig) {
invalidateSchemaCacheForProject(projectConfig: GraphQLProjectConfig) {
const schemaKey = this._getSchemaCacheKeyForProject(
projectConfig,
) as string;
Expand Down
14 changes: 14 additions & 0 deletions packages/graphql-language-service-server/src/MessageProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -1138,6 +1140,18 @@ export class MessageProcessor {
await this._graphQLCache.updateFragmentDefinition(rootDir, uri, contents);
}

async _updateSchemaIfChanged(
project: GraphQLProjectConfig,
uri: Uri,
): Promise<void> {
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[],
Expand Down

0 comments on commit 0aeebd7

Please sign in to comment.