Skip to content

Commit

Permalink
address comment
Browse files Browse the repository at this point in the history
  • Loading branch information
vvakame committed Aug 1, 2018
1 parent bf43ab3 commit 4fb721a
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 23 deletions.
2 changes: 1 addition & 1 deletion codegen/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ type TypeMapEntry struct {

type TypeMapField struct {
Resolver bool `yaml:"resolver"`
ModelName string `yaml:"modelField"`
FieldName string `yaml:"fieldName"`
}

func (c *PackageConfig) normalize() error {
Expand Down
16 changes: 7 additions & 9 deletions codegen/input_build.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,18 @@ func (cfg *Config) buildInput(types NamedTypes, typ *ast.Definition) (*Object, e
typeEntry, entryExists := cfg.Models[typ.Name]

for _, field := range typ.Fields {
var goVarName string
newField := Field{
GQLName: field.Name,
Type: types.getType(field.Type),
Object: obj,
}

if entryExists {
if typeField, ok := typeEntry.Fields[field.Name]; ok {
goVarName = typeField.ModelName
newField.GoFieldName = typeField.FieldName
}
}

newField := Field{
GQLName: field.Name,
Type: types.getType(field.Type),
Object: obj,
GoFieldName: goVarName,
}

if field.DefaultValue != nil {
var err error
newField.Default, err = field.DefaultValue.Value(nil)
Expand Down
2 changes: 1 addition & 1 deletion codegen/object_build.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ func (cfg *Config) buildObject(types NamedTypes, typ *ast.Definition, imports *I
var goName string
if entryExists {
if typeField, ok := typeEntry.Fields[field.Name]; ok {
goName = typeField.ModelName
goName = typeField.FieldName
forceResolver = typeField.Resolver
}
}
Expand Down
6 changes: 3 additions & 3 deletions example/config/.gqlgen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ models:
Todo: # Object
fields:
text:
modelField: Description # Field
fieldName: Description # Field
NewTodo: # Input
fields:
userId:
modelField: UserID # Field
fieldName: UserID # Field
User:
model: github.com/vektah/gqlgen/example/config.User
fields:
name:
modelField: FullName # Method
fieldName: FullName # Method
9 changes: 0 additions & 9 deletions example/config/server/server.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
package main

import (
"context"
"errors"
"log"
"net/http"
"runtime/debug"

todo "github.com/vektah/gqlgen/example/config"
"github.com/vektah/gqlgen/handler"
Expand All @@ -15,12 +12,6 @@ func main() {
http.Handle("/", handler.Playground("Todo", "/query"))
http.Handle("/query", handler.GraphQL(
todo.NewExecutableSchema(todo.New()),
handler.RecoverFunc(func(ctx context.Context, err interface{}) error {
// send this panic somewhere
log.Print(err)
debug.PrintStack()
return errors.New("user message on panic")
}),
))
log.Fatal(http.ListenAndServe(":8081", nil))
}

0 comments on commit 4fb721a

Please sign in to comment.