@@ -154,17 +154,32 @@ private List<string> DefaultTemplates(string outputPath)
154154 public IEnumerable < CodeGeneratorSettings > GenerateSettings ( CodeGeneratorSettingsLoaderDefaults settings , IEnumerable < string > paths )
155155 {
156156 var root = Directory . GetCurrentDirectory ( ) ;
157- IEnumerable < string > sourceFilePaths = paths . SelectMany ( x => GlobExpander . FindFiles ( root , x ) ) ;
158157
159- var sourceFiles = sourceFilePaths . Select ( x => Load ( x , settings ) ) . ToList ( ) ;
158+ // we need to multi pass the source files looking for items to load
159+ var toProcess = new Queue < string > ( paths . SelectMany ( x => GlobExpander . FindFiles ( root , x ) ) ) ;
160+ List < SimpleSourceFile > sourceFiles = new List < SimpleSourceFile > ( ) ;
161+ List < string > processedPaths = new List < string > ( ) ;
162+ while ( toProcess . Any ( ) )
163+ {
164+ var path = toProcess . Dequeue ( ) ;
165+ processedPaths . Add ( path ) ;
166+ var loaded = Load ( path , settings ) ;
167+ var newPaths = loaded . Includes . Where ( x => ! processedPaths . Contains ( x ) ) ;
168+ foreach ( var p in newPaths )
169+ {
170+ toProcess . Enqueue ( p ) ;
171+ }
172+ sourceFiles . Add ( loaded ) ;
173+
174+ }
160175
161176 var grouped = sourceFiles . GroupBy ( x => new
162177 {
163178 x . ClassName ,
164179 x . OutputPath ,
165180 x . Format ,
166181 hash = x . SettingsHash ( )
167- } ) ;
182+ } ) . ToList ( ) ;
168183
169184
170185 return grouped . Select ( x =>
@@ -213,6 +228,9 @@ internal class SimpleSettings
213228 [ JsonConverter ( typeof ( SingleOrArrayConverter < string > ) ) ]
214229 public List < string > Template { get ; set ; }
215230
231+ [ JsonConverter ( typeof ( SingleOrArrayConverter < string > ) ) ]
232+ public List < string > Include { get ; set ; }
233+
216234 public bool Root { get ; set ; } = false ;
217235 }
218236
@@ -230,7 +248,6 @@ private void LoadSettingsTree(SimpleSourceFile file)
230248 {
231249 Stack < SimpleSettings > settingsList = new Stack < SimpleSettings > ( ) ;
232250 var directory = Path . GetDirectoryName ( file . Path ) ;
233- var rooted = false ;
234251 while ( directory != null )
235252 {
236253 var settingsFile = Path . Combine ( directory , "gqlsettings.json" ) ;
@@ -300,6 +317,10 @@ private SimpleSourceFile Load(string path, CodeGeneratorSettingsLoaderDefaults s
300317 var templateFiles = GlobExpander . FindFiles ( root , m . val ) ;
301318 file . Templates . AddRange ( templateFiles ) ;
302319 break ;
320+ case "include" :
321+ var includeFiles = GlobExpander . FindFiles ( root , m . val ) ;
322+ file . Includes . AddRange ( includeFiles ) ;
323+ break ;
303324 default :
304325 break ;
305326 }
@@ -375,6 +396,15 @@ private bool ExpandSettings(string path, SimpleSourceFile file)
375396 }
376397 }
377398
399+ if ( settings . Include != null )
400+ {
401+ foreach ( var t in settings . Include )
402+ {
403+ var files = GlobExpander . FindFiles ( root , t ) ;
404+ file . Includes . AddRange ( files ) ;
405+ }
406+ }
407+
378408 if ( string . IsNullOrWhiteSpace ( file . SchemaSource ? . Location ) )
379409 {
380410 if ( settings . Schema != null && ! string . IsNullOrWhiteSpace ( settings . Schema . Location ) )
@@ -429,6 +459,7 @@ internal class SimpleSourceFile
429459 public string ClassName { get ; set ; }
430460 public string OutputPath { get ; set ; }
431461 public List < string > Templates { get ; set ; } = new List < string > ( ) ;
462+ public List < string > Includes { get ; set ; } = new List < string > ( ) ;
432463 public SchemaSource SchemaSource { get ; set ; }
433464
434465 internal string SettingsHash ( )
0 commit comments