diff --git a/api/generate.go b/api/generate.go index e0238e5602d..45f8af31b54 100644 --- a/api/generate.go +++ b/api/generate.go @@ -15,13 +15,15 @@ import ( func Generate(cfg *config.Config, option ...Option) error { _ = syscall.Unlink(cfg.Exec.Filename) - _ = syscall.Unlink(cfg.Model.Filename) + if cfg.Model.IsDefined() { + _ = syscall.Unlink(cfg.Model.Filename) + } - plugins := []plugin.Plugin{ - schemaconfig.New(), - modelgen.New(), - resolvergen.New(), + plugins := []plugin.Plugin{schemaconfig.New()} + if cfg.Model.IsDefined() { + plugins = append(plugins, modelgen.New()) } + plugins = append(plugins, resolvergen.New()) for _, o := range option { o(cfg, &plugins) diff --git a/codegen/config/config.go b/codegen/config/config.go index 45f8a7bd81a..1771237e856 100644 --- a/codegen/config/config.go +++ b/codegen/config/config.go @@ -22,7 +22,7 @@ import ( type Config struct { SchemaFilename StringList `yaml:"schema,omitempty"` Exec PackageConfig `yaml:"exec"` - Model PackageConfig `yaml:"model"` + Model PackageConfig `yaml:"model,omitempty"` Resolver PackageConfig `yaml:"resolver,omitempty"` AutoBind []string `yaml:"autobind"` Models TypeMap `yaml:"models,omitempty"` @@ -228,8 +228,10 @@ func (c *Config) Check() error { if err := c.Exec.Check(); err != nil { return errors.Wrap(err, "config.exec") } - if err := c.Model.Check(); err != nil { - return errors.Wrap(err, "config.model") + if c.Model.IsDefined() { + if err := c.Model.Check(); err != nil { + return errors.Wrap(err, "config.model") + } } if c.Resolver.IsDefined() { if err := c.Resolver.Check(); err != nil { @@ -239,11 +241,14 @@ func (c *Config) Check() error { // check packages names against conflict, if present in the same dir // and check filenames for uniqueness - packageConfigList := []PackageConfig{ - c.Model, + packageConfigList := []PackageConfig{} + if c.Model.IsDefined() { + packageConfigList = append(packageConfigList, c.Model) + } + packageConfigList = append(packageConfigList, []PackageConfig{ c.Exec, c.Resolver, - } + }...) filesMap := make(map[string]bool) pkgConfigsByDir := make(map[string]PackageConfig) for _, current := range packageConfigList { @@ -364,8 +369,10 @@ func findCfgInDir(dir string) string { } func (c *Config) normalize() error { - if err := c.Model.normalize(); err != nil { - return errors.Wrap(err, "model") + if c.Model.IsDefined() { + if err := c.Model.normalize(); err != nil { + return errors.Wrap(err, "model") + } } if err := c.Exec.normalize(); err != nil { diff --git a/docs/content/config.md b/docs/content/config.md index 00902352dad..a7fd8ac9649 100644 --- a/docs/content/config.md +++ b/docs/content/config.md @@ -33,6 +33,7 @@ exec: package: generated # Let gqlgen know where to put the generated models (if any) +# Set to null to disable model: filename: models/generated.go package: models