1- import { Source , Maybe , isSome } from '@graphql-tools/utils' ;
1+ import { Source } from '@graphql-tools/utils' ;
22import { env } from 'process' ;
33import { LoadTypedefsOptions } from '../load-typedefs' ;
44
5- export async function loadFile ( pointer : string , options : LoadTypedefsOptions ) : Promise < Maybe < Source [ ] > > {
5+ export async function loadFile ( pointer : string , options : LoadTypedefsOptions ) : Promise < Source [ ] > {
66 const cached = useCache ( { pointer, options } ) ;
77
88 if ( cached ) {
99 return cached ;
1010 }
1111
12- for await ( const loader of options . loaders ) {
13- try {
14- const loadedValue = await loader . load ( pointer , options ) ;
15- if ( ! isSome ( loadedValue ) || loadedValue . length === 0 ) {
16- continue ;
17- }
18- return loadedValue ;
19- } catch ( error ) {
20- if ( env [ 'DEBUG' ] ) {
21- console . error ( `Failed to find any GraphQL type definitions in: ${ pointer } - ${ error . message } ` ) ;
12+ const results : Source [ ] = [ ] ;
13+
14+ await Promise . all (
15+ options . loaders . map ( async loader => {
16+ try {
17+ const loaderResults = await loader . load ( pointer , options ) ;
18+ loaderResults ?. forEach ( result => results . push ( result ) ) ;
19+ } catch ( error ) {
20+ if ( env [ 'DEBUG' ] ) {
21+ console . error ( `Failed to find any GraphQL type definitions in: ${ pointer } - ${ error . message } ` ) ;
22+ }
23+ throw error ;
2224 }
23- throw error ;
24- }
25- }
25+ } )
26+ ) ;
2627
27- return undefined ;
28+ return results ;
2829}
2930
30- export function loadFileSync ( pointer : string , options : LoadTypedefsOptions ) : Maybe < Source [ ] > {
31+ export function loadFileSync ( pointer : string , options : LoadTypedefsOptions ) : Source [ ] {
3132 const cached = useCache ( { pointer, options } ) ;
3233
3334 if ( cached ) {
3435 return cached ;
3536 }
3637
38+ const results : Source [ ] = [ ] ;
39+
3740 for ( const loader of options . loaders ) {
3841 try {
3942 // We check for the existence so it is okay to force non null
40- const loadedValue = loader . loadSync ! ( pointer , options ) ;
41- if ( ! isSome ( loadedValue ) || loadedValue . length === 0 ) {
42- continue ;
43- }
44- return loadedValue ;
43+ const loaderResults = loader . loadSync ! ( pointer , options ) ;
44+ loaderResults ?. forEach ( result => results . push ( result ) ) ;
4545 } catch ( error ) {
4646 if ( env [ 'DEBUG' ] ) {
4747 console . error ( `Failed to find any GraphQL type definitions in: ${ pointer } - ${ error . message } ` ) ;
@@ -50,7 +50,7 @@ export function loadFileSync(pointer: string, options: LoadTypedefsOptions): May
5050 }
5151 }
5252
53- return undefined ;
53+ return results ;
5454}
5555
5656function useCache < T extends any > ( { pointer, options } : { pointer : string ; options : T } ) {
0 commit comments