Skip to content

Commit 632a7c6

Browse files
scamdenacao
authored andcommitted
GraphQLCache: fix multiple projects in one graphqlrc
1 parent 63762fd commit 632a7c6

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

.changeset/short-bears-taste.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'graphql-language-service-server': patch
3+
---
4+
5+
allow caching for multiple projects in graphql config

packages/graphql-language-service-server/src/GraphQLCache.ts

+14-8
Original file line numberDiff line numberDiff line change
@@ -179,23 +179,28 @@ export class GraphQLCache implements GraphQLCacheInterface {
179179
return referencedFragments;
180180
};
181181

182+
_cacheKeyForProject = ({ dirpath, name }: GraphQLProjectConfig): string => {
183+
return `${dirpath}-${name}`;
184+
};
185+
182186
getFragmentDefinitions = async (
183187
projectConfig: GraphQLProjectConfig,
184188
): Promise<Map<string, FragmentInfo>> => {
185189
// This function may be called from other classes.
186190
// If then, check the cache first.
187191
const rootDir = projectConfig.dirpath;
188-
if (this._fragmentDefinitionsCache.has(rootDir)) {
189-
return this._fragmentDefinitionsCache.get(rootDir) || new Map();
192+
const cacheKey = this._cacheKeyForProject(projectConfig);
193+
if (this._fragmentDefinitionsCache.has(cacheKey)) {
194+
return this._fragmentDefinitionsCache.get(cacheKey) || new Map();
190195
}
191196

192197
const list = await this._readFilesFromInputDirs(rootDir, projectConfig);
193198

194199
const { fragmentDefinitions, graphQLFileMap } =
195200
await this.readAllGraphQLFiles(list);
196201

197-
this._fragmentDefinitionsCache.set(rootDir, fragmentDefinitions);
198-
this._graphQLFileListCache.set(rootDir, graphQLFileMap);
202+
this._fragmentDefinitionsCache.set(cacheKey, fragmentDefinitions);
203+
this._graphQLFileListCache.set(cacheKey, graphQLFileMap);
199204

200205
return fragmentDefinitions;
201206
};
@@ -286,14 +291,15 @@ export class GraphQLCache implements GraphQLCacheInterface {
286291
// This function may be called from other classes.
287292
// If then, check the cache first.
288293
const rootDir = projectConfig.dirpath;
289-
if (this._typeDefinitionsCache.has(rootDir)) {
290-
return this._typeDefinitionsCache.get(rootDir) || new Map();
294+
const cacheKey = this._cacheKeyForProject(projectConfig);
295+
if (this._typeDefinitionsCache.has(cacheKey)) {
296+
return this._typeDefinitionsCache.get(cacheKey) || new Map();
291297
}
292298
const list = await this._readFilesFromInputDirs(rootDir, projectConfig);
293299
const { objectTypeDefinitions, graphQLFileMap } =
294300
await this.readAllGraphQLFiles(list);
295-
this._typeDefinitionsCache.set(rootDir, objectTypeDefinitions);
296-
this._graphQLFileListCache.set(rootDir, graphQLFileMap);
301+
this._typeDefinitionsCache.set(cacheKey, objectTypeDefinitions);
302+
this._graphQLFileListCache.set(cacheKey, graphQLFileMap);
297303

298304
return objectTypeDefinitions;
299305
};

0 commit comments

Comments
 (0)