Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ForceGenerate parameter to @goModel added. #2780

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions codegen/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,13 +281,20 @@ func (c *Config) injectTypesFromSchema() error {
c.Models.Add(schemaType.Name, mv.(string))
}
}

if ma := bd.Arguments.ForName("models"); ma != nil {
if mvs, err := ma.Value.Value(nil); err == nil {
for _, mv := range mvs.([]interface{}) {
c.Models.Add(schemaType.Name, mv.(string))
}
}
}

if fg := bd.Arguments.ForName("forceGenerate"); fg != nil {
if mv, err := fg.Value.Value(nil); err == nil {
c.Models.ForceGenerate(schemaType.Name, mv.(bool))
}
}
}

if schemaType.Kind == ast.Object || schemaType.Kind == ast.InputObject {
Expand Down Expand Up @@ -329,8 +336,9 @@ func (c *Config) injectTypesFromSchema() error {
}

type TypeMapEntry struct {
Model StringList `yaml:"model"`
Fields map[string]TypeMapField `yaml:"fields,omitempty"`
Model StringList `yaml:"model,omitempty"`
ForceGenerate bool `yaml:"forceGenerate,omitempty"`
Fields map[string]TypeMapField `yaml:"fields,omitempty"`

// Key is the Go name of the field.
ExtraFields map[string]ModelExtraField `yaml:"extraFields,omitempty"`
Expand Down Expand Up @@ -529,6 +537,12 @@ func (tm TypeMap) Add(name string, goType string) {
tm[name] = modelCfg
}

func (tm TypeMap) ForceGenerate(name string, forceGenerate bool) {
modelCfg := tm[name]
modelCfg.ForceGenerate = forceGenerate
tm[name] = modelCfg
}

type DirectiveConfig struct {
SkipRuntime bool `yaml:"skip_runtime"`
}
Expand Down Expand Up @@ -587,6 +601,11 @@ func (c *Config) autobind() error {
continue
}

if c.Models[t.Name].ForceGenerate {
delete(c.Models, t.Name)
continue
}

for i, p := range ps {
if p == nil || p.Module == nil {
return fmt.Errorf("unable to load %s - make sure you're using an import path to a package that exists", c.AutoBind[i])
Expand Down
3 changes: 2 additions & 1 deletion docs/content/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,13 @@ To start using them you first need to define them:
directive @goModel(
model: String
models: [String!]
forceGenerate: Boolean
) on OBJECT | INPUT_OBJECT | SCALAR | ENUM | INTERFACE | UNION

directive @goField(
forceResolver: Boolean
name: String
omittable: Boolean
omittable: Boolean
) on INPUT_FIELD_DEFINITION | FIELD_DEFINITION

directive @goTag(
Expand Down