6
6
"github.com/99designs/gqlgen/codegen"
7
7
"github.com/99designs/gqlgen/codegen/config"
8
8
"github.com/99designs/gqlgen/plugin"
9
+ "github.com/99designs/gqlgen/plugin/federation"
9
10
"github.com/99designs/gqlgen/plugin/modelgen"
10
11
"github.com/99designs/gqlgen/plugin/resolvergen"
11
12
"github.com/99designs/gqlgen/plugin/schemaconfig"
@@ -18,17 +19,33 @@ func Generate(cfg *config.Config, option ...Option) error {
18
19
if cfg .Model .IsDefined () {
19
20
_ = syscall .Unlink (cfg .Model .Filename )
20
21
}
22
+ if err := cfg .Check (); err != nil {
23
+ return errors .Wrap (err , "generating core failed" )
24
+ }
21
25
22
26
plugins := []plugin.Plugin {schemaconfig .New ()}
23
27
if cfg .Model .IsDefined () {
24
28
plugins = append (plugins , modelgen .New ())
25
29
}
26
30
plugins = append (plugins , resolvergen .New ())
31
+ if cfg .Federated {
32
+ plugins = append ([]plugin.Plugin {federation .New ()}, plugins ... )
33
+ }
27
34
28
35
for _ , o := range option {
29
36
o (cfg , & plugins )
30
37
}
31
38
39
+ schemaMutators := []codegen.SchemaMutator {}
40
+ for _ , p := range plugins {
41
+ if inj , ok := p .(plugin.SourcesInjector ); ok {
42
+ inj .InjectSources (cfg )
43
+ }
44
+ if mut , ok := p .(codegen.SchemaMutator ); ok {
45
+ schemaMutators = append (schemaMutators , mut )
46
+ }
47
+ }
48
+
32
49
for _ , p := range plugins {
33
50
if mut , ok := p .(plugin.ConfigMutator ); ok {
34
51
err := mut .MutateConfig (cfg )
@@ -38,7 +55,7 @@ func Generate(cfg *config.Config, option ...Option) error {
38
55
}
39
56
}
40
57
// Merge again now that the generated models have been injected into the typemap
41
- data , err := codegen .BuildData (cfg )
58
+ data , err := codegen .BuildData (cfg , schemaMutators )
42
59
if err != nil {
43
60
return errors .Wrap (err , "merging type systems failed" )
44
61
}
@@ -56,6 +73,10 @@ func Generate(cfg *config.Config, option ...Option) error {
56
73
}
57
74
}
58
75
76
+ if err = codegen .GenerateCode (data ); err != nil {
77
+ return errors .Wrap (err , "generating core failed" )
78
+ }
79
+
59
80
if ! cfg .SkipValidation {
60
81
if err := validate (cfg ); err != nil {
61
82
return errors .Wrap (err , "validation failed" )
0 commit comments