@@ -8,6 +8,7 @@ import { buildSchema, GraphQLSchema } from 'graphql';
8
8
import { GraphQLConfig } from 'graphql-config' ;
9
9
import { dirname } from 'path' ;
10
10
import { ParserOptions } from './types' ;
11
+ import { getOnDiskFilepath } from './utils' ;
11
12
12
13
const schemaCache : Map < string , GraphQLSchema > = new Map ( ) ;
13
14
@@ -32,26 +33,24 @@ export function getSchema(options: ParserOptions, gqlConfig: GraphQLConfig): Gra
32
33
33
34
// We first try to use graphql-config for loading the schema, based on the type of the file,
34
35
// We are using the directory of the file as the key for the schema caching, to avoid reloading of the schema.
35
- if ( gqlConfig && options ?. filePath ) {
36
- const fileDir = dirname ( options . filePath ) ;
36
+ if ( gqlConfig && options . filePath ) {
37
+ const realFilepath = getOnDiskFilepath ( options . filePath ) ;
38
+ const projectForFile = gqlConfig . getProjectForFile ( realFilepath ) ;
39
+ const schemaKey = projectForFile . schema . toString ( ) ;
37
40
38
- if ( schemaCache . has ( fileDir ) ) {
39
- schema = schemaCache . get ( fileDir ) ;
41
+ if ( schemaCache . has ( schemaKey ) ) {
42
+ schema = schemaCache . get ( schemaKey ) ;
40
43
} else {
41
- const projectForFile = gqlConfig . getProjectForFile ( options . filePath ) ;
42
-
43
- if ( projectForFile ) {
44
- schema = projectForFile . getSchemaSync ( ) ;
45
- schemaCache . set ( fileDir , schema ) ;
46
- }
44
+ schema = projectForFile . getSchemaSync ( ) ;
45
+ schemaCache . set ( schemaKey , schema ) ;
47
46
}
48
47
}
49
48
50
49
// If schema was not loaded yet, and user configured it in the parserConfig, we can try to load it,
51
50
// In this case, the cache key is the path for the schema. This is needed in order to allow separate
52
51
// configurations for different file paths (a very edgey case).
53
- if ( ! schema && options ? .schema ) {
54
- const schemaKey = Array . isArray ( options . schema ) ? options . schema . join ( ',' ) : options . schema ;
52
+ if ( ! schema && options . schema ) {
53
+ const schemaKey = options . schema . toString ( ) ;
55
54
56
55
if ( schemaCache . has ( schemaKey ) ) {
57
56
schema = schemaCache . get ( schemaKey ) ;
0 commit comments