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

Made choice of whether to use slice-of-struct-pointers vs slice-of-st… #719

Closed
wants to merge 1 commit into from
Closed
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
5 changes: 5 additions & 0 deletions codegen/config/binder.go
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,11 @@ func (b *Binder) TypeReference(schemaType *ast.Type, bindTarget types.Type) (ret

func (b *Binder) CopyModifiersFromAst(t *ast.Type, base types.Type) types.Type {
if t.Elem != nil {
if b.cfg.Tweaks != nil && b.cfg.Tweaks.UseStructValueSlices {
// Pre 0.9 behavior
return types.NewSlice(b.CopyModifiersFromAst(t.Elem, base))
}

child := b.CopyModifiersFromAst(t.Elem, base)
if _, isStruct := child.Underlying().(*types.Struct); isStruct {
child = types.NewPointer(child)
Expand Down
7 changes: 7 additions & 0 deletions codegen/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ type Config struct {
Resolver PackageConfig `yaml:"resolver,omitempty"`
Models TypeMap `yaml:"models,omitempty"`
StructTag string `yaml:"struct_tag,omitempty"`
Tweaks *TweakSet `yaml:"tweaks,omitempty"`
}

var cfgFilenames = []string{".gqlgen.yml", "gqlgen.yml", "gqlgen.yaml"}
Expand Down Expand Up @@ -408,3 +409,9 @@ func abs(path string) string {
}
return filepath.ToSlash(absPath)
}

// A TweakSet is a config object instructing the binder to override
// certain default behavior.
type TweakSet struct {
UseStructValueSlices bool `yaml:"use_struct_value_slices"`
}
Loading