This repository was archived by the owner on Sep 2, 2020. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +27
-2
lines changed Expand file tree Collapse file tree 3 files changed +27
-2
lines changed Original file line number Diff line number Diff line change @@ -243,6 +243,11 @@ export class GraphQLCache implements GraphQLCacheInterface {
243243 includes : string [ ] ,
244244 ) : Promise < Array < GraphQLFileMetadata >> => {
245245 let pattern : string ;
246+
247+ if ( includes . length === 0 ) {
248+ return Promise . resolve ( [ ] ) ;
249+ }
250+
246251 // See https://github.com/graphql/graphql-language-service/issues/221
247252 // for details on why special handling is required here for the
248253 // includes.length === 1 case.
@@ -251,6 +256,7 @@ export class GraphQLCache implements GraphQLCacheInterface {
251256 } else {
252257 pattern = `{${ includes . join ( ',' ) } }` ;
253258 }
259+
254260 return new Promise ( ( resolve , reject ) => {
255261 const globResult = new glob . Glob (
256262 pattern ,
Original file line number Diff line number Diff line change 3636 "schemaPath": "__schema__/StarWarsSchema.graphql",
3737 "includes": [ "__queries__/*.graphql" ]
3838 },
39- "testSingularMultipleIncludes ": {
39+ "testMultipleIncludes ": {
4040 "schemaPath": "__schema__/StarWarsSchema.graphql",
4141 "includes": [
4242 "__queries__/*.graphql",
4343 "__fragments__/*.graphql"
4444 ]
45+ },
46+ "testNoIncludes": {
47+ "schemaPath": "__schema__/StarWarsSchema.graphql"
48+ },
49+ "testBadIncludes": {
50+ "schemaPath": "__schema__/StarWarsSchema.graphql",
51+ "includes": ["nope.nopeql"]
4552 }
4653 },
4754 "extensions": {
Original file line number Diff line number Diff line change @@ -166,9 +166,21 @@ describe('GraphQLCache', () => {
166166 } ) ;
167167
168168 it ( 'it caches fragments found through multiple globs in `includes`' , async ( ) => {
169- const config = graphQLRC . getProjectConfig ( 'testSingularMultipleIncludes ' ) ;
169+ const config = graphQLRC . getProjectConfig ( 'testMultipleIncludes ' ) ;
170170 const fragmentDefinitions = await cache . getFragmentDefinitions ( config ) ;
171171 expect ( fragmentDefinitions . get ( 'testFragment' ) ) . to . not . be . undefined ;
172172 } ) ;
173+
174+ it ( 'handles empty includes' , async ( ) => {
175+ const config = graphQLRC . getProjectConfig ( 'testNoIncludes' ) ;
176+ const fragmentDefinitions = await cache . getFragmentDefinitions ( config ) ;
177+ expect ( fragmentDefinitions . get ( 'testFragment' ) ) . to . be . undefined ;
178+ } ) ;
179+
180+ it ( 'handles non-existent includes' , async ( ) => {
181+ const config = graphQLRC . getProjectConfig ( 'testBadIncludes' ) ;
182+ const fragmentDefinitions = await cache . getFragmentDefinitions ( config ) ;
183+ expect ( fragmentDefinitions . get ( 'testFragment' ) ) . to . be . undefined ;
184+ } ) ;
173185 } ) ;
174186} ) ;
You can’t perform that action at this time.
0 commit comments