From daa8aeafaf010aac4828c5cd25301f934b768024 Mon Sep 17 00:00:00 2001 From: Hooman Yar Date: Wed, 6 Oct 2021 01:22:59 -0700 Subject: [PATCH] Add a config option to skip running "go mod tidy" on code generation --- api/generate.go | 7 +++++-- codegen/config/config.go | 1 + docs/content/config.md | 3 +++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/api/generate.go b/api/generate.go index 8d4b88de69d..6a85cd941ac 100644 --- a/api/generate.go +++ b/api/generate.go @@ -77,8 +77,11 @@ func Generate(cfg *config.Config, option ...Option) error { if err = codegen.GenerateCode(data); err != nil { return fmt.Errorf("generating core failed: %w", err) } - if err = cfg.Packages.ModTidy(); err != nil { - return fmt.Errorf("tidy failed: %w", err) + + if !cfg.SkipModTidy { + if err = cfg.Packages.ModTidy(); err != nil { + return fmt.Errorf("tidy failed: %w", err) + } } for _, p := range plugins { diff --git a/codegen/config/config.go b/codegen/config/config.go index 404befada20..56bfc6090d6 100644 --- a/codegen/config/config.go +++ b/codegen/config/config.go @@ -27,6 +27,7 @@ type Config struct { Directives map[string]DirectiveConfig `yaml:"directives,omitempty"` OmitSliceElementPointers bool `yaml:"omit_slice_element_pointers,omitempty"` SkipValidation bool `yaml:"skip_validation,omitempty"` + SkipModTidy bool `yaml:"skip_mod_tidy,omitempty"` Sources []*ast.Source `yaml:"-"` Packages *code.Packages `yaml:"-"` Schema *ast.Schema `yaml:"-"` diff --git a/docs/content/config.md b/docs/content/config.md index 21cfa328ffb..6ed8c900fba 100644 --- a/docs/content/config.md +++ b/docs/content/config.md @@ -46,6 +46,9 @@ resolver: # Optional: set to speed up generation time by not performing a final validation pass. # skip_validation: true +# Optional: set to skip running `go mod tidy` when generating server code +# skip_mod_tidy: true + # gqlgen will search for any type names in the schema in these go packages # if they match it will use them, otherwise it will generate them. autobind: