From be8e9feb665921eff5660f46e992e1c15f47919b Mon Sep 17 00:00:00 2001 From: Aaron Moat <2937187+AaronMoat@users.noreply.github.com> Date: Sun, 7 May 2023 18:14:14 +1000 Subject: [PATCH] Fix GraphQLCache to read both documents and schema --- .changeset/shy-starfishes-clap.md | 5 ++++ .../src/GraphQLCache.ts | 30 ++++++++++++------- 2 files changed, 25 insertions(+), 10 deletions(-) create mode 100644 .changeset/shy-starfishes-clap.md diff --git a/.changeset/shy-starfishes-clap.md b/.changeset/shy-starfishes-clap.md new file mode 100644 index 00000000000..cb966a48792 --- /dev/null +++ b/.changeset/shy-starfishes-clap.md @@ -0,0 +1,5 @@ +--- +'graphql-language-service-server': minor +--- + +Fix GraphQLCache to read both documents and schema diff --git a/packages/graphql-language-service-server/src/GraphQLCache.ts b/packages/graphql-language-service-server/src/GraphQLCache.ts index 006c065106c..07166687740 100644 --- a/packages/graphql-language-service-server/src/GraphQLCache.ts +++ b/packages/graphql-language-service-server/src/GraphQLCache.ts @@ -323,22 +323,16 @@ export class GraphQLCache implements GraphQLCacheInterface { projectConfig: GraphQLProjectConfig, ): Promise> => { let pattern: string; - const { documents } = projectConfig; - - if (!documents || documents.length === 0) { - return Promise.resolve([]); - } + const patterns = this._getSchemaAndDocumentFilePatterns(projectConfig); // See https://github.com/graphql/graphql-language-service/issues/221 // for details on why special handling is required here for the // documents.length === 1 case. - if (typeof documents === 'string') { - pattern = documents; - } else if (documents.length === 1) { + if (patterns.length === 1) { // @ts-ignore - pattern = documents[0]; + pattern = patterns[0]; } else { - pattern = `{${documents.join(',')}}`; + pattern = `{${patterns.join(',')}}`; } return new Promise((resolve, reject) => { @@ -388,6 +382,22 @@ export class GraphQLCache implements GraphQLCacheInterface { }); }; + _getSchemaAndDocumentFilePatterns = (projectConfig: GraphQLProjectConfig) => { + const patterns: string[] = []; + + for (const pointer of [projectConfig.documents, projectConfig.schema]) { + if (pointer) { + if (typeof pointer === 'string') { + patterns.push(pointer); + } else if (Array.isArray(pointer)) { + patterns.push(...pointer); + } + } + } + + return patterns; + }; + async _updateGraphQLFileListCache( graphQLFileMap: Map, metrics: { size: number; mtime: number },