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

Resolver method to nested model not created #350

Closed
marczahn opened this issue Sep 20, 2018 · 5 comments
Closed

Resolver method to nested model not created #350

marczahn opened this issue Sep 20, 2018 · 5 comments

Comments

@marczahn
Copy link

Expected Behaviour

For a relation Card -> Question I expect in the card resolver a method like

func (r *cardResolver) Question(ctx context.Context, obj *models.Card) (models.Question, error) {
	panic("not implemented")
}

Actual Behavior

There is no method for this

Minimal graphql.schema and models to reproduce

same configuration as here

@marczahn
Copy link
Author

I just found out that the resolver method is created as soon as the sub entity is specified as a list in the graphql.schema.

Is this a bug or is there a reason why it is like this?

@vektah
Copy link
Collaborator

vektah commented Sep 20, 2018

If you want a resolver method when generating models use resolver: true.

eg:

models:
  Todo:
    fields:
      id:
        resolver: true # force a resolver to be generated

see https://gqlgen.com/config/

@vektah vektah closed this as completed Sep 20, 2018
@marczahn
Copy link
Author

marczahn commented Sep 20, 2018

Hey @vektah
thank you! It is working indeed - I overlooked this. Nevertheless: It is unexpected that there are resolvers created for lists per default.

@bobheadxi
Copy link

I agree with @marczahn here, I spent a pretty long time scratching my head as to how to deal with nested models, and this doesn't seem very clearly documented.

Also the nested model in the example https://github.com/99designs/gqlgen/blob/master/example/starwars/schema.graphql#L33 doesn't seem to have the resolver: true directive in its config for friendsConnection: https://github.com/99designs/gqlgen/blob/master/example/starwars/.gqlgen.yml

Could you clarify this a little @vektah ? thanks!

@kainosnoema
Copy link

Two years later, it still took me a full day of reading gqlgen docs (finding nothing) and finally Googling to find this issue and realize that generated nested models don't automatically create resolvers.

@vektah @frederikhors I've seen you mention a couple places that the docs explain how to do this, but it's still VERY confusing (as can be seen by the number of confused devs opening these issues still). It seemed completely broken for me.... had no idea why it wasn't working. Maybe could update the docs to better explain what's needed to generate resolvers? I'd recommend a section describing resolver generation here (not mentioned anywhere there): https://gqlgen.com/config

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

No branches or pull requests

4 participants