@@ -179,23 +179,28 @@ export class GraphQLCache implements GraphQLCacheInterface {
179
179
return referencedFragments ;
180
180
} ;
181
181
182
+ _cacheKeyForProject = ( { dirpath, name } : GraphQLProjectConfig ) : string => {
183
+ return `${ dirpath } -${ name } ` ;
184
+ } ;
185
+
182
186
getFragmentDefinitions = async (
183
187
projectConfig : GraphQLProjectConfig ,
184
188
) : Promise < Map < string , FragmentInfo > > => {
185
189
// This function may be called from other classes.
186
190
// If then, check the cache first.
187
191
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 ( ) ;
190
195
}
191
196
192
197
const list = await this . _readFilesFromInputDirs ( rootDir , projectConfig ) ;
193
198
194
199
const { fragmentDefinitions, graphQLFileMap } =
195
200
await this . readAllGraphQLFiles ( list ) ;
196
201
197
- this . _fragmentDefinitionsCache . set ( rootDir , fragmentDefinitions ) ;
198
- this . _graphQLFileListCache . set ( rootDir , graphQLFileMap ) ;
202
+ this . _fragmentDefinitionsCache . set ( cacheKey , fragmentDefinitions ) ;
203
+ this . _graphQLFileListCache . set ( cacheKey , graphQLFileMap ) ;
199
204
200
205
return fragmentDefinitions ;
201
206
} ;
@@ -286,14 +291,15 @@ export class GraphQLCache implements GraphQLCacheInterface {
286
291
// This function may be called from other classes.
287
292
// If then, check the cache first.
288
293
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 ( ) ;
291
297
}
292
298
const list = await this . _readFilesFromInputDirs ( rootDir , projectConfig ) ;
293
299
const { objectTypeDefinitions, graphQLFileMap } =
294
300
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 ) ;
297
303
298
304
return objectTypeDefinitions ;
299
305
} ;
0 commit comments