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

Mutation and Query returns interface #1689

Closed
frederikhors opened this issue Nov 3, 2021 · 2 comments
Closed

Mutation and Query returns interface #1689

frederikhors opened this issue Nov 3, 2021 · 2 comments

Comments

@frederikhors
Copy link
Collaborator

frederikhors commented Nov 3, 2021

What happened?

I just updated to golangci-lint v1.43 today and I'm getting this warning from ireturn:

image

Mutation returns interface (project/internal/gqlgen.MutationResolver) (ireturn)
Query returns interface (project/internal/gqlgen.QueryResolver) (ireturn)

What did you expect?

Maybe we should stop to return interface in that methods.

Minimal graphql.schema and models to reproduce

  • schema.graphql:
type Query

type Mutation

versions

  • gqlgen version? github.com/99designs/gqlgen v0.14.0
  • go version? go version go1.17.2 windows/amd64
  • dep or go modules? go.mod
@duckbrain
Copy link
Contributor

It sounds like the linter is overly strict. Returning interfaces is perfectly valid when you're implementing another interface. (Which this is doing.) By changing the methods (and the interfaces they implement) to structs, you could no longer implement the Resolver interface with anything but the generated resolvers.

Source: Rob Pike mentions this as a problematic proverb go-proverbs/go-proverbs.github.io#37 (comment)

@martinscholz83
Copy link

Can is ask a question on this issue? Returning Interface I think it’s fine. But Query() and Mutation() always return a new pointer to their resolver implementation for every call. Wouldn’t that mean we would have a lot of objects which needs to be deleted by GC?

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

3 participants