@@ -83,6 +83,7 @@ export class GraphQLCache implements GraphQLCacheInterface {
83
83
getFragmentDependencies = async (
84
84
query : string ,
85
85
fragmentDefinitions : ?Map < string , FragmentInfo > ,
86
+ projectConfig : GraphQLProjectConfig ,
86
87
) : Promise < Array < FragmentInfo >> => {
87
88
// If there isn't context for fragment references,
88
89
// return an empty array.
@@ -93,7 +94,7 @@ export class GraphQLCache implements GraphQLCacheInterface {
93
94
// Return an empty array.
94
95
let parsedQuery ;
95
96
try {
96
- parsedQuery = parse ( query ) ;
97
+ parsedQuery = parse ( query , projectConfig . parseOptions ) ;
97
98
} catch ( error ) {
98
99
return [ ] ;
99
100
}
@@ -183,6 +184,7 @@ export class GraphQLCache implements GraphQLCacheInterface {
183
184
getObjectTypeDependencies = async (
184
185
query : string ,
185
186
objectTypeDefinitions : ?Map < string , ObjectTypeInfo > ,
187
+ projectConfig : GraphQLProjectConfig ,
186
188
) : Promise < Array < ObjectTypeInfo >> => {
187
189
// If there isn't context for object type references,
188
190
// return an empty array.
@@ -193,7 +195,7 @@ export class GraphQLCache implements GraphQLCacheInterface {
193
195
// Return an empty array.
194
196
let parsedQuery ;
195
197
try {
196
- parsedQuery = parse ( query ) ;
198
+ parsedQuery = parse ( query , projectConfig . parseOptions ) ;
197
199
} catch ( error ) {
198
200
return [ ] ;
199
201
}
@@ -320,7 +322,7 @@ export class GraphQLCache implements GraphQLCacheInterface {
320
322
return ;
321
323
}
322
324
323
- const fileAndContent = await this . promiseToReadGraphQLFile ( filePath ) ;
325
+ const fileAndContent = await this . promiseToReadGraphQLFile ( filePath , projectConfig ) ;
324
326
graphQLFileMap . set ( filePath , {
325
327
...fileAndContent ,
326
328
size,
@@ -337,6 +339,7 @@ export class GraphQLCache implements GraphQLCacheInterface {
337
339
{ size, mtime} ,
338
340
filePath ,
339
341
exists ,
342
+ projectConfig ,
340
343
) ,
341
344
) ;
342
345
}
@@ -413,9 +416,10 @@ export class GraphQLCache implements GraphQLCacheInterface {
413
416
metrics : { size : number , mtime : number } ,
414
417
filePath : Uri ,
415
418
exists : boolean ,
419
+ projectConfig : GraphQLProjectConfig ,
416
420
) : Promise < Map < Uri , GraphQLFileInfo >> {
417
421
const fileAndContent = exists
418
- ? await this . promiseToReadGraphQLFile ( filePath )
422
+ ? await this . promiseToReadGraphQLFile ( filePath , projectConfig )
419
423
: null ;
420
424
const graphQLFileInfo = { ...fileAndContent , ...metrics } ;
421
425
@@ -438,11 +442,12 @@ export class GraphQLCache implements GraphQLCacheInterface {
438
442
rootDir: Uri ,
439
443
filePath : Uri ,
440
444
contents : Array < CachedContent > ,
445
+ projectConfig : GraphQLProjectConfig ,
441
446
) : Promise < void > {
442
447
const cache = this . _fragmentDefinitionsCache . get ( rootDir ) ;
443
448
const asts = contents . map ( ( { query} ) => {
444
449
try {
445
- return { ast : parse ( query ) , query } ;
450
+ return { ast : parse ( query , projectConfig . parseOptions ) , query} ;
446
451
} catch ( error ) {
447
452
return { ast : null , query} ;
448
453
}
@@ -475,9 +480,10 @@ export class GraphQLCache implements GraphQLCacheInterface {
475
480
rootDir : Uri ,
476
481
filePath : Uri ,
477
482
exists : boolean ,
483
+ projectConfig : GraphQLProjectConfig ,
478
484
) : Promise < void > {
479
485
const fileAndContent = exists
480
- ? await this . promiseToReadGraphQLFile ( filePath )
486
+ ? await this . promiseToReadGraphQLFile ( filePath , projectConfig )
481
487
: null ;
482
488
// In the case of fragment definitions, the cache could just map the
483
489
// definition name to the parsed ast, whether or not it existed
@@ -489,19 +495,20 @@ export class GraphQLCache implements GraphQLCacheInterface {
489
495
cache . delete ( filePath ) ;
490
496
}
491
497
} else if ( fileAndContent && fileAndContent . queries ) {
492
- this . updateFragmentDefinition ( rootDir , filePath , fileAndContent . queries ) ;
498
+ this . updateFragmentDefinition ( rootDir , filePath , fileAndContent . queries , projectConfig ) ;
493
499
}
494
500
}
495
501
496
502
async updateObjectTypeDefinition (
497
503
rootDir: Uri ,
498
504
filePath : Uri ,
499
505
contents : Array < CachedContent > ,
506
+ projectConfig : GraphQLProjectConfig ,
500
507
) : Promise < void > {
501
508
const cache = this . _typeDefinitionsCache . get ( rootDir ) ;
502
509
const asts = contents . map ( ( { query} ) => {
503
510
try {
504
- return { ast : parse ( query ) , query } ;
511
+ return { ast : parse ( query , projectConfig . parseOptions ) , query} ;
505
512
} catch ( error ) {
506
513
return { ast : null , query} ;
507
514
}
@@ -538,6 +545,7 @@ export class GraphQLCache implements GraphQLCacheInterface {
538
545
rootDir : Uri ,
539
546
filePath : Uri ,
540
547
exists : boolean ,
548
+ projectConfig : GraphQLProjectConfig ,
541
549
) : Promise < void > {
542
550
const fileAndContent = exists
543
551
? await this . promiseToReadGraphQLFile ( filePath )
@@ -623,16 +631,10 @@ export class GraphQLCache implements GraphQLCacheInterface {
623
631
}
624
632
625
633
getSchema = async (
626
- appName : ? string ,
634
+ projectConfig : GraphQLProjectConfig ,
627
635
queryHasExtensions ?: ?boolean = false ,
628
636
) : Promise < ?GraphQLSchema > => {
629
- const projectConfig = this . _graphQLConfig . getProjectConfig ( appName ) ;
630
-
631
- if ( ! projectConfig ) {
632
- return null ;
633
- }
634
-
635
- const projectName = appName || 'undefinedName' ;
637
+ const projectName = projectConfig . projectName || 'undefinedName' ;
636
638
const schemaPath = projectConfig . schemaPath ;
637
639
const endpointInfo = this . _getDefaultEndpoint ( projectConfig ) ;
638
640
@@ -678,7 +680,7 @@ export class GraphQLCache implements GraphQLCacheInterface {
678
680
const customDirectives = projectConfig . extensions . customDirectives ;
679
681
if ( customDirectives && schema ) {
680
682
const directivesSDL = customDirectives . join ( '\n\n' ) ;
681
- schema = extendSchema ( schema , parse ( directivesSDL ) ) ;
683
+ schema = extendSchema ( schema , parse ( directivesSDL , projectConfig . parseOptions ) ) ;
682
684
}
683
685
684
686
if ( ! schema ) {
@@ -826,6 +828,7 @@ export class GraphQLCache implements GraphQLCacheInterface {
826
828
*/
827
829
promiseToReadGraphQLFile = (
828
830
filePath : Uri ,
831
+ projectConfig : GraphQLProjectConfig ,
829
832
) : Promise < {
830
833
filePath : Uri ,
831
834
content : string ,
@@ -850,7 +853,7 @@ export class GraphQLCache implements GraphQLCacheInterface {
850
853
return ;
851
854
}
852
855
853
- queries . forEach ( ( { query} ) => asts . push ( parse ( query ) ) ) ;
856
+ queries . forEach ( ( { query} ) => asts . push ( parse ( query , projectConfig . parseOptions ) ) ) ;
854
857
} catch ( _ ) {
855
858
// If query has syntax errors, go ahead and still resolve
856
859
// the filePath and the content, but leave ast empty.
0 commit comments