Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix GraphQLCache to read both documents and schema #3163

Merged
merged 1 commit into from
May 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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