Skip to content

Commit

Permalink
Fix underscore only fields
Browse files Browse the repository at this point in the history
closes #473
  • Loading branch information
vektah authored and Adam Scarr committed Feb 18, 2019
1 parent 0eb8b5c commit 8c2d15e
Show file tree
Hide file tree
Showing 19 changed files with 274 additions and 243 deletions.
4 changes: 2 additions & 2 deletions codegen/field.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,10 @@ func (b *builder) bindField(obj *Object, f *Field) error {
case obj.Type == config.MapType:
return nil
case b.Config.Models[obj.Name].Fields[f.Name].FieldName != "":
f.Name = b.Config.Models[obj.Name].Fields[f.Name].FieldName
f.GoFieldName = b.Config.Models[obj.Name].Fields[f.Name].FieldName
}

target, err := b.findBindTarget(obj.Type.(*types.Named), f.Name)
target, err := b.findBindTarget(obj.Type.(*types.Named), f.GoFieldName)
if err != nil {
return err
}
Expand Down
8 changes: 4 additions & 4 deletions codegen/generated!.gotpl
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ type ComplexityRoot struct {
{{ $object.Name|toCamel }} struct {
{{ range $field := $object.Fields -}}
{{ if not $field.IsReserved -}}
{{ $field.Name|toCamel }} {{ $field.ComplexitySignature }}
{{ $field.GoFieldName }} {{ $field.ComplexitySignature }}
{{ end }}
{{- end }}
}
Expand Down Expand Up @@ -86,8 +86,8 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in
{{ if not $object.IsReserved }}
{{ range $field := $object.Fields }}
{{ if not $field.IsReserved }}
case "{{$object.Name}}.{{$field.Name}}":
if e.complexity.{{$object.Name|toCamel}}.{{$field.Name|toCamel}} == nil {
case "{{$object.Name}}.{{$field.GoFieldName}}":
if e.complexity.{{$object.Name|toCamel}}.{{$field.GoFieldName}} == nil {
break
}
{{ if $field.Args }}
Expand All @@ -96,7 +96,7 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in
return 0, false
}
{{ end }}
return e.complexity.{{$object.Name|toCamel}}.{{$field.Name|toCamel}}(childComplexity{{if $field.Args}}, {{$field.ComplexityArgs}} {{end}}), true
return e.complexity.{{$object.Name|toCamel}}.{{$field.GoFieldName}}(childComplexity{{if $field.Args}}, {{$field.ComplexityArgs}} {{end}}), true
{{ end }}
{{ end }}
{{ end }}
Expand Down
4 changes: 4 additions & 0 deletions codegen/templates/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,9 @@ func Call(p *types.Func) string {
}

func ToCamel(s string) string {
if s == "_" {
return "_"
}
buffer := make([]rune, 0, len(s))
upper := true
lastWasUpper := false
Expand Down Expand Up @@ -288,6 +291,7 @@ var keywords = []string{
"import",
"return",
"var",
"_",
}

// sanitizeKeywords prevents collisions with go keywords for arguments to resolver functions
Expand Down
Loading

0 comments on commit 8c2d15e

Please sign in to comment.