@@ -39,7 +39,13 @@ public CodeGenerator(ILogger logger, CodeGeneratorSettings settings, IEnumerable
3939 this . introspectionProviders = introspectionProviders ;
4040 }
4141
42- public async Task < bool > GenerateAsync ( )
42+ internal IEnumerable < NamedSource > Sources { get ; set ; }
43+ internal ObjectModel . GraphQLDocument Document { get ; set ; }
44+ internal Models . ViewModel Model { get ; set ; }
45+ internal string GeneratedCode { get ; set ; }
46+ internal bool HasParsingErrors { get ; set ; }
47+
48+ internal async Task LoadSource ( )
4349 {
4450 IIntrosepctionProvider provider = this . introspectionProviders . Single ( x => x . SchemaType == this . settings . Schema . SchemaType ( ) ) ;
4551
@@ -52,28 +58,57 @@ public async Task<bool> GenerateAsync()
5258 {
5359 sources . Add ( s ) ;
5460 }
55- // we want to track the file that the operation is loaded from
56- // lets make a locatino index look up table and provide it
57- ObjectModel . GraphQLDocument doc = Parse ( sources ) ;
5861
59- if ( doc . Errors . Any ( ) )
62+ Sources = sources ;
63+ }
64+
65+ internal void Export ( )
66+ {
67+ Directory . CreateDirectory ( Path . GetDirectoryName ( this . settings . OutputPath ) ) ;
68+ File . WriteAllText ( this . settings . OutputPath , GeneratedCode ) ;
69+ }
70+
71+ internal void Render ( )
72+ {
73+ this . GeneratedCode = new TemplateEngine ( this . settings . Templates , logger ) . Generate ( Model ) ;
74+ }
75+
76+ internal void Parse ( )
77+ {
78+ Document = IntrospectedSchemeParser . Parse ( Sources ) ;
79+
80+ if ( Document . Errors . Any ( ) )
6081 {
61- foreach ( var error in doc . Errors )
82+ foreach ( var error in Document . Errors )
6283 {
6384 logger . Error ( error . ToString ( ) ) ;
6485 }
86+ HasParsingErrors = true ;
87+ return ;
88+ }
89+
90+ Model = new Models . ViewModel ( Document , this . settings ) ;
91+
92+ HasParsingErrors = false ;
93+ }
94+
95+ public async Task < bool > GenerateAsync ( )
96+ {
97+ await LoadSource ( ) ;
98+
99+ Parse ( ) ;
100+
101+ if ( HasParsingErrors )
102+ {
65103 return false ;
66104 }
67105
68- Models . ViewModel model = new Models . ViewModel ( doc , this . settings ) ;
106+ Render ( ) ;
69107
70- string fileResult = new TemplateEngine ( this . settings . Templates , logger ) . Generate ( model ) ;
108+ Export ( ) ;
71109
72- Directory . CreateDirectory ( Path . GetDirectoryName ( this . settings . OutputPath ) ) ;
73- File . WriteAllText ( this . settings . OutputPath , fileResult ) ;
74110 return true ;
75111 }
76-
77112 }
78113
79114 public class CodeGeneratorSettings
0 commit comments