@@ -6,7 +6,6 @@ import { readFileSync, promises as fsPromises, existsSync } from 'fs';
66import { cwd as processCwd } from 'process' ;
77import { processImport } from '@graphql-tools/import' ;
88import globby from 'globby' ;
9- import isGlob from 'is-glob' ;
109import unixify from 'unixify' ;
1110
1211const { readFile, access } = fsPromises ;
@@ -61,11 +60,6 @@ export class GraphQLFileLoader implements Loader<GraphQLFileLoaderOptions> {
6160 }
6261
6362 async canLoad ( pointer : string , options : GraphQLFileLoaderOptions ) : Promise < boolean > {
64- if ( isGlob ( pointer ) ) {
65- // FIXME: parse to find and check the file extensions?
66- return true ;
67- }
68-
6963 if ( isValidPath ( pointer ) ) {
7064 if ( FILE_EXTENSIONS . find ( extension => pointer . endsWith ( extension ) ) ) {
7165 const normalizedFilePath = isAbsolute ( pointer ) ? pointer : resolve ( options . cwd || processCwd ( ) , pointer ) ;
@@ -82,66 +76,56 @@ export class GraphQLFileLoader implements Loader<GraphQLFileLoaderOptions> {
8276 }
8377
8478 canLoadSync ( pointer : string , options : GraphQLFileLoaderOptions ) : boolean {
85- if ( isGlob ( pointer ) ) {
86- // FIXME: parse to find and check the file extensions?
87- return true ;
88- }
89-
9079 if ( isValidPath ( pointer ) ) {
9180 if ( FILE_EXTENSIONS . find ( extension => pointer . endsWith ( extension ) ) ) {
9281 const normalizedFilePath = isAbsolute ( pointer ) ? pointer : resolve ( options . cwd || processCwd ( ) , pointer ) ;
9382 return existsSync ( normalizedFilePath ) ;
9483 }
9584 }
96-
9785 return false ;
9886 }
9987
10088 async resolveGlobs ( glob : string , options : GraphQLFileLoaderOptions ) {
10189 const ignores = asArray ( options . ignore || [ ] ) ;
102- return globby ( [ glob , ...ignores . map ( v => `!(${ v } )` ) . map ( v => unixify ( v ) ) ] , createGlobbyOptions ( options ) ) ;
90+ const target = [ glob , ...ignores . map ( v => `!${ v } ` ) . map ( v => unixify ( v ) ) ] ;
91+ const result = await globby ( target , createGlobbyOptions ( options ) ) ;
92+ return result ;
10393 }
10494
10595 resolveGlobsSync ( glob : string , options : GraphQLFileLoaderOptions ) {
10696 const ignores = asArray ( options . ignore || [ ] ) ;
107- return globby . sync ( [ glob , ...ignores . map ( v => `!(${ v } )` ) . map ( v => unixify ( v ) ) ] , createGlobbyOptions ( options ) ) ;
97+ const target = [ glob , ...ignores . map ( v => `!${ v } ` ) . map ( v => unixify ( v ) ) ] ;
98+ const result = globby . sync ( target , createGlobbyOptions ( options ) ) ;
99+ return result ;
108100 }
109101
110102 async load ( pointer : string , options : GraphQLFileLoaderOptions ) : Promise < Source [ ] > {
111- if ( isGlob ( pointer ) ) {
112- const resolvedPaths = await this . resolveGlobs ( pointer , options ) ;
113- const finalResult : Source [ ] = [ ] ;
114- await Promise . all (
115- resolvedPaths . map ( async path => {
116- if ( await this . canLoad ( path , options ) ) {
117- const result = await this . load ( path , options ) ;
118- result ?. forEach ( result => finalResult . push ( result ) ) ;
119- }
120- } )
121- ) ;
122- return finalResult ;
123- }
124- const normalizedFilePath = isAbsolute ( pointer ) ? pointer : resolve ( options . cwd || processCwd ( ) , pointer ) ;
125- const rawSDL : string = await readFile ( normalizedFilePath , { encoding : 'utf8' } ) ;
126-
127- return [ this . handleFileContent ( rawSDL , normalizedFilePath , options ) ] ;
103+ const resolvedPaths = await this . resolveGlobs ( pointer , options ) ;
104+ const finalResult : Source [ ] = [ ] ;
105+
106+ await Promise . all (
107+ resolvedPaths . map ( async path => {
108+ if ( await this . canLoad ( path , options ) ) {
109+ const normalizedFilePath = isAbsolute ( path ) ? path : resolve ( options . cwd || processCwd ( ) , path ) ;
110+ const rawSDL : string = await readFile ( normalizedFilePath , { encoding : 'utf8' } ) ;
111+ finalResult . push ( this . handleFileContent ( rawSDL , normalizedFilePath , options ) ) ;
112+ }
113+ } )
114+ ) ;
115+ return finalResult ;
128116 }
129117
130118 loadSync ( pointer : string , options : GraphQLFileLoaderOptions ) : Source [ ] {
131- if ( isGlob ( pointer ) ) {
132- const resolvedPaths = this . resolveGlobsSync ( pointer , options ) ;
133- const finalResult : Source [ ] = [ ] ;
134- for ( const path of resolvedPaths ) {
135- if ( this . canLoadSync ( path , options ) ) {
136- const result = this . loadSync ( path , options ) ;
137- result ?. forEach ( result => finalResult . push ( result ) ) ;
138- }
119+ const resolvedPaths = this . resolveGlobsSync ( pointer , options ) ;
120+ const finalResult : Source [ ] = [ ] ;
121+ for ( const path of resolvedPaths ) {
122+ if ( this . canLoadSync ( path , options ) ) {
123+ const normalizedFilePath = isAbsolute ( path ) ? path : resolve ( options . cwd || processCwd ( ) , path ) ;
124+ const rawSDL = readFileSync ( normalizedFilePath , { encoding : 'utf8' } ) ;
125+ finalResult . push ( this . handleFileContent ( rawSDL , normalizedFilePath , options ) ) ;
139126 }
140- return finalResult ;
141127 }
142- const normalizedFilePath = isAbsolute ( pointer ) ? pointer : resolve ( options . cwd || processCwd ( ) , pointer ) ;
143- const rawSDL = readFileSync ( normalizedFilePath , { encoding : 'utf8' } ) ;
144- return [ this . handleFileContent ( rawSDL , normalizedFilePath , options ) ] ;
128+ return finalResult ;
145129 }
146130
147131 handleFileContent ( rawSDL : string , pointer : string , options : GraphQLFileLoaderOptions ) {
0 commit comments