@@ -2,13 +2,29 @@ import { GraphQLFileLoader } from '@graphql-tools/graphql-file-loader';
2
2
import { JsonFileLoader } from '@graphql-tools/json-file-loader' ;
3
3
import { loadSchemaSync } from '@graphql-tools/load' ;
4
4
import { UrlLoader } from '@graphql-tools/url-loader' ;
5
+ import { Loader , SingleFileOptions } from '@graphql-tools/utils' ;
5
6
import { buildSchema , GraphQLSchema } from 'graphql' ;
6
7
import { GraphQLConfig } from 'graphql-config' ;
7
8
import { dirname } from 'path' ;
8
9
import { ParserOptions } from './types' ;
9
10
10
11
const schemaCache : Map < string , GraphQLSchema > = new Map ( ) ;
11
12
13
+ export const schemaLoaders : Loader < string , SingleFileOptions > [ ] = [
14
+ {
15
+ loaderId : ( ) => 'direct-string' ,
16
+ canLoad : async ( ) => false ,
17
+ load : async ( ) => null ,
18
+ canLoadSync : pointer => typeof pointer === 'string' && pointer . includes ( 'type ' ) ,
19
+ loadSync : pointer => ( {
20
+ schema : buildSchema ( pointer ) ,
21
+ } ) ,
22
+ } ,
23
+ new GraphQLFileLoader ( ) ,
24
+ new JsonFileLoader ( ) ,
25
+ new UrlLoader ( ) ,
26
+ ]
27
+
12
28
export function getSchema ( options : ParserOptions , gqlConfig : GraphQLConfig ) : GraphQLSchema | null {
13
29
let schema : GraphQLSchema | null = null ;
14
30
@@ -44,20 +60,7 @@ export function getSchema(options: ParserOptions, gqlConfig: GraphQLConfig): Gra
44
60
schema = loadSchemaSync ( options . schema , {
45
61
...( options . schemaOptions || { } ) ,
46
62
assumeValidSDL : true ,
47
- loaders : [
48
- {
49
- loaderId : ( ) => 'direct-string' ,
50
- canLoad : async ( ) => false ,
51
- load : async ( ) => null ,
52
- canLoadSync : pointer => typeof pointer === 'string' && pointer . includes ( 'type ' ) ,
53
- loadSync : pointer => ( {
54
- schema : buildSchema ( pointer ) ,
55
- } ) ,
56
- } ,
57
- new GraphQLFileLoader ( ) ,
58
- new JsonFileLoader ( ) ,
59
- new UrlLoader ( ) ,
60
- ] ,
63
+ loaders : schemaLoaders ,
61
64
} ) ;
62
65
schemaCache . set ( schemaKey , schema ) ;
63
66
} catch ( e ) {
0 commit comments