Skip to content

Commit

Permalink
Fix GraphQLCache to read both documents and schema
Browse files Browse the repository at this point in the history
  • Loading branch information
AaronMoat committed May 7, 2023
1 parent 1d60e9a commit be8e9fe
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 10 deletions.
5 changes: 5 additions & 0 deletions .changeset/shy-starfishes-clap.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'graphql-language-service-server': minor
---

Fix GraphQLCache to read both documents and schema
30 changes: 20 additions & 10 deletions packages/graphql-language-service-server/src/GraphQLCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -323,22 +323,16 @@ export class GraphQLCache implements GraphQLCacheInterface {
projectConfig: GraphQLProjectConfig,
): Promise<Array<GraphQLFileMetadata>> => {
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) => {
Expand Down Expand Up @@ -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<Uri, GraphQLFileInfo>,
metrics: { size: number; mtime: number },
Expand Down

0 comments on commit be8e9fe

Please sign in to comment.