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 +36
-8
lines changed Expand file tree Collapse file tree 3 files changed +36
-8
lines changed Original file line number Diff line number Diff line change @@ -158,13 +158,9 @@ export class GraphQLCache implements GraphQLCacheInterface {
158158 return this . _fragmentDefinitionsCache . get ( rootDir ) || new Map ( ) ;
159159 }
160160
161- const includes = projectConfig . includes . map (
162- filePath => filePath . split ( '*' ) [ 0 ] ,
163- ) ;
164-
165161 const filesFromInputDirs = await this . _readFilesFromInputDirs (
166162 rootDir ,
167- includes ,
163+ projectConfig . includes ,
168164 ) ;
169165 const list = filesFromInputDirs . filter ( fileInfo =>
170166 projectConfig . includesFile ( fileInfo . filePath ) ,
@@ -246,9 +242,18 @@ export class GraphQLCache implements GraphQLCacheInterface {
246242 rootDir : string ,
247243 includes : string [ ] ,
248244 ) : Promise < Array < GraphQLFileMetadata >> => {
245+ let pattern : string ;
246+ // See https://github.com/graphql/graphql-language-service/issues/221
247+ // for details on why special handling is required here for the
248+ // includes.length === 1 case.
249+ if ( includes . length === 1 ) {
250+ pattern = includes [ 0 ] ;
251+ } else {
252+ pattern = `{${ includes . join ( ',' ) } }` ;
253+ }
249254 return new Promise ( ( resolve , reject ) => {
250255 const globResult = new glob . Glob (
251- `{ ${ includes . join ( ',' ) } }/**/*.{js,graphql}` ,
256+ pattern ,
252257 {
253258 cwd : rootDir ,
254259 stat : true ,
Original file line number Diff line number Diff line change 11{
2- "includes": ["__queries__"],
3- "excludes": ["__excludedQueries__"],
42 "projects": {
53 "testWithSchema": {
64 "schemaPath": "__schema__/StarWarsSchema.graphql"
3331 "directive @customDirective on FIELD"
3432 ]
3533 }
34+ },
35+ "testSingularIncludesGlob": {
36+ "schemaPath": "__schema__/StarWarsSchema.graphql",
37+ "includes": [ "__queries__/*.graphql" ]
38+ },
39+ "testSingularMultipleIncludes": {
40+ "schemaPath": "__schema__/StarWarsSchema.graphql",
41+ "includes": [
42+ "__queries__/*.graphql",
43+ "__fragments__/*.graphql"
44+ ]
3645 }
3746 },
3847 "extensions": {
Original file line number Diff line number Diff line change @@ -157,4 +157,18 @@ describe('GraphQLCache', () => {
157157 expect ( result . length ) . to . equal ( 1 ) ;
158158 } ) ;
159159 } ) ;
160+
161+ describe ( 'getFragmentDefinitions' , ( ) => {
162+ it ( 'it caches fragments found through single glob in `includes`' , async ( ) => {
163+ const config = graphQLRC . getProjectConfig ( 'testSingularIncludesGlob' ) ;
164+ const fragmentDefinitions = await cache . getFragmentDefinitions ( config ) ;
165+ expect ( fragmentDefinitions . get ( 'testFragment' ) ) . to . not . be . undefined ;
166+ } ) ;
167+
168+ it ( 'it caches fragments found through multiple globs in `includes`' , async ( ) => {
169+ const config = graphQLRC . getProjectConfig ( 'testSingularMultipleIncludes' ) ;
170+ const fragmentDefinitions = await cache . getFragmentDefinitions ( config ) ;
171+ expect ( fragmentDefinitions . get ( 'testFragment' ) ) . to . not . be . undefined ;
172+ } ) ;
173+ } ) ;
160174} ) ;
You can’t perform that action at this time.
0 commit comments