diff --git a/codegen/config/config.go b/codegen/config/config.go index 92c4aeb99a..5b85097596 100644 --- a/codegen/config/config.go +++ b/codegen/config/config.go @@ -23,6 +23,7 @@ type Config struct { Exec PackageConfig `yaml:"exec"` Model PackageConfig `yaml:"model"` Resolver PackageConfig `yaml:"resolver,omitempty"` + Service PackageConfig `yaml:"service,omitempty"` AutoBind []string `yaml:"autobind"` Models TypeMap `yaml:"models,omitempty"` StructTag string `yaml:"struct_tag,omitempty"` @@ -39,6 +40,7 @@ func DefaultConfig() *Config { SchemaFilename: StringList{"schema.graphql"}, Model: PackageConfig{Filename: "models_gen.go"}, Exec: PackageConfig{Filename: "generated.go"}, + Service: PackageConfig{Filename: "service.go"}, Directives: map[string]DirectiveConfig{}, } } @@ -236,6 +238,11 @@ func (c *Config) Check() error { return errors.Wrap(err, "config.resolver") } } + if c.Service.IsDefined() { + if err := c.Service.Check(); err != nil { + return errors.Wrap(err, "config.service") + } + } // check packages names against conflict, if present in the same dir // and check filenames for uniqueness @@ -243,6 +250,7 @@ func (c *Config) Check() error { c.Model, c.Exec, c.Resolver, + c.Service, } filesMap := make(map[string]bool) pkgConfigsByDir := make(map[string]PackageConfig) @@ -378,6 +386,12 @@ func (c *Config) normalize() error { } } + if c.Service.IsDefined() { + if err := c.Service.normalize(); err != nil { + return errors.Wrap(err, "service") + } + } + if c.Models == nil { c.Models = TypeMap{} } diff --git a/plugin/federation/federation.go b/plugin/federation/federation.go index f19838844f..aaec3fd018 100644 --- a/plugin/federation/federation.go +++ b/plugin/federation/federation.go @@ -209,8 +209,8 @@ func (f *federation) GenerateCode(data *codegen.Data) error { } return templates.Render(templates.Options{ Template: tmpl, - PackageName: data.Config.Exec.Package, - Filename: "service.go", + PackageName: data.Config.Service.Package, + Filename: data.Config.Service.Filename, Data: f, GeneratedHeader: true, })