-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Add model field mapping #237
Conversation
codegen/config.go
Outdated
@@ -78,7 +78,8 @@ type TypeMapEntry struct { | |||
} | |||
|
|||
type TypeMapField struct { | |||
Resolver bool `yaml:"resolver"` | |||
Resolver bool `yaml:"resolver"` | |||
GoVarName string `yaml:"govarname"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@vektah do you like this naming?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤔
What about binding to methods?
eg
Todo:
model: github.com/my/app/models.Todo
fields:
id:
modelField: IDString
to bind to
func (t *Todo) IdString() string {
return ...
}
what about fieldName
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@vektah plz take a look again.
- rename to
fieldName
- support binding to method & field both
appveyor is little bit flaky...? 🤔 |
Yeah, it doesn't deal with test concurrency well, maybe their machines are overloaded. I've been meaning to take a look, but there are bigger fish to fry. |
codegen/input_build.go
Outdated
|
||
for _, field := range typ.Fields { | ||
var goVarName string | ||
if entryExists { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if you did this after creating feild you can drop the temp var
if typeEntry, entryExists := cfg.Models[typ.Name] ; entryExists {
if typeField, ok := typeEntry.Fields[field.Name]; ok {
newField.GoFieldName = typeField.ModelName
}
}
example/config/server/server.go
Outdated
"net/http" | ||
"runtime/debug" | ||
|
||
todo "github.com/vektah/gqlgen/example/config" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
aliased todo?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ya, I copied from example/todo . I thought that config
was a bit confusing
example/config/server/server.go
Outdated
http.Handle("/", handler.Playground("Todo", "/query")) | ||
http.Handle("/query", handler.GraphQL( | ||
todo.NewExecutableSchema(todo.New()), | ||
handler.RecoverFunc(func(ctx context.Context, err interface{}) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this was copied from todo, might as well drop the error stuff?
codegen/config.go
Outdated
@@ -78,7 +78,8 @@ type TypeMapEntry struct { | |||
} | |||
|
|||
type TypeMapField struct { | |||
Resolver bool `yaml:"resolver"` | |||
Resolver bool `yaml:"resolver"` | |||
ModelName string `yaml:"modelField"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fieldName?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🙀
Add model field mapping
closes #198