@@ -8,6 +8,7 @@ import { buildSchema, GraphQLSchema } from 'graphql';
88import { GraphQLConfig } from 'graphql-config' ;
99import { dirname } from 'path' ;
1010import { ParserOptions } from './types' ;
11+ import { getOnDiskFilepath } from './utils' ;
1112
1213const schemaCache : Map < string , GraphQLSchema > = new Map ( ) ;
1314
@@ -32,26 +33,24 @@ export function getSchema(options: ParserOptions, gqlConfig: GraphQLConfig): Gra
3233
3334 // We first try to use graphql-config for loading the schema, based on the type of the file,
3435 // 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 ( ) ;
3740
38- if ( schemaCache . has ( fileDir ) ) {
39- schema = schemaCache . get ( fileDir ) ;
41+ if ( schemaCache . has ( schemaKey ) ) {
42+ schema = schemaCache . get ( schemaKey ) ;
4043 } 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 ) ;
4746 }
4847 }
4948
5049 // If schema was not loaded yet, and user configured it in the parserConfig, we can try to load it,
5150 // In this case, the cache key is the path for the schema. This is needed in order to allow separate
5251 // 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 ( ) ;
5554
5655 if ( schemaCache . has ( schemaKey ) ) {
5756 schema = schemaCache . get ( schemaKey ) ;
0 commit comments