@@ -60,7 +60,6 @@ export class JsonFileLoader implements Loader {
6060 if ( isValidPath ( pointer ) ) {
6161 if ( FILE_EXTENSIONS . find ( extension => pointer . endsWith ( extension ) ) ) {
6262 const normalizedFilePath = isAbsolute ( pointer ) ? pointer : resolve ( options . cwd || cwd ( ) , pointer ) ;
63-
6463 return existsSync ( normalizedFilePath ) ;
6564 }
6665 }
@@ -70,6 +69,9 @@ export class JsonFileLoader implements Loader {
7069
7170 async load ( pointer : string , options : JsonFileLoaderOptions ) : Promise < Source [ ] > {
7271 const normalizedFilePath = isAbsolute ( pointer ) ? pointer : resolve ( options . cwd || cwd ( ) , pointer ) ;
72+ if ( ! ( await this . canLoad ( normalizedFilePath , options ) ) ) {
73+ return [ ] ;
74+ }
7375
7476 try {
7577 const jsonContent : string = await readFile ( normalizedFilePath , { encoding : 'utf8' } ) ;
@@ -80,13 +82,16 @@ export class JsonFileLoader implements Loader {
8082 }
8183
8284 loadSync ( pointer : string , options : JsonFileLoaderOptions ) : Source [ ] {
83- const normalizedFilepath = isAbsolute ( pointer ) ? pointer : resolve ( options . cwd || cwd ( ) , pointer ) ;
85+ const normalizedFilePath = isAbsolute ( pointer ) ? pointer : resolve ( options . cwd || cwd ( ) , pointer ) ;
86+ if ( ! this . canLoadSync ( normalizedFilePath , options ) ) {
87+ return [ ] ;
88+ }
8489
8590 try {
86- const jsonContent = readFileSync ( normalizedFilepath , 'utf8' ) ;
91+ const jsonContent = readFileSync ( normalizedFilePath , 'utf8' ) ;
8792 return [ parseGraphQLJSON ( pointer , jsonContent , options ) ] ;
8893 } catch ( e ) {
89- throw new Error ( `Unable to read JSON file: ${ normalizedFilepath } : ${ e . message || /* istanbul ignore next */ e } ` ) ;
94+ throw new Error ( `Unable to read JSON file: ${ normalizedFilePath } : ${ e . message || /* istanbul ignore next */ e } ` ) ;
9095 }
9196 }
9297}
0 commit comments