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

Add model field mapping #237

Merged
merged 6 commits into from
Aug 1, 2018
Merged

Add model field mapping #237

merged 6 commits into from
Aug 1, 2018

Conversation

vvakame
Copy link
Collaborator

@vvakame vvakame commented Jul 31, 2018

closes #198

@vvakame vvakame requested a review from vektah July 31, 2018 12:21
@@ -78,7 +78,8 @@ type TypeMapEntry struct {
}

type TypeMapField struct {
Resolver bool `yaml:"resolver"`
Resolver bool `yaml:"resolver"`
GoVarName string `yaml:"govarname"`
Copy link
Collaborator Author

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?

Copy link
Collaborator

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?

Copy link
Collaborator Author

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.

  1. rename to fieldName
  2. support binding to method & field both

@vvakame
Copy link
Collaborator Author

vvakame commented Jul 31, 2018

@vvakame
Copy link
Collaborator Author

vvakame commented Aug 1, 2018

appveyor is little bit flaky...? 🤔

@vektah
Copy link
Collaborator

vektah commented Aug 1, 2018

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.


for _, field := range typ.Fields {
var goVarName string
if entryExists {
Copy link
Collaborator

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
    }
}

"net/http"
"runtime/debug"

todo "github.com/vektah/gqlgen/example/config"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

aliased todo?

Copy link
Collaborator Author

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

http.Handle("/", handler.Playground("Todo", "/query"))
http.Handle("/query", handler.GraphQL(
todo.NewExecutableSchema(todo.New()),
handler.RecoverFunc(func(ctx context.Context, err interface{}) error {
Copy link
Collaborator

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?

@@ -78,7 +78,8 @@ type TypeMapEntry struct {
}

type TypeMapField struct {
Resolver bool `yaml:"resolver"`
Resolver bool `yaml:"resolver"`
ModelName string `yaml:"modelField"`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fieldName?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🙀

@vektah vektah merged commit 6b53238 into next Aug 1, 2018
@vvakame vvakame deleted the feat-fieldmapping branch August 1, 2018 07:26
cgxxv pushed a commit to cgxxv/gqlgen that referenced this pull request Mar 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants