gqlgen: 0.17.14 generate getters for interfaces problem
What happened?
When upgrading to 0.17.14 my code generation started to fail due to the new generation of getters for interfaces. It’s due to interfaces returning other interfaces I think.
What did you expect?
Code generation to result in valid code
Minimal graphql.schema and models to reproduce
Reproduction repo: https://github.com/argoyle/gqlgen-implements
versions
go run github.com/99designs/gqlgen version
? 0.17.14go version
? 1.19
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 1
- Comments: 24 (16 by maintainers)
This is an interesting one. Looking at the schema (https://github.com/argoyle/gqlgen-implements/blob/main/graph/schema.graphqls), we have
UsersConnection implements Connection
, but… it doesn’t look like it actually does. Theedges
field onUsersConnection
is[UsersEdge!]!
, but theedges
field in theConnection
interface is[Edge!]!
.Even though
UsersEdge implements Edge
is true, I’m pretty sure[UsersEdge!]! implements [Edge!]!
isn’t, i.e., even if every element inedges
is aUsersEdge
, I’m fairly positive the type onedges
still needs to be[Edge!]!
.I can see if the GraphQL spec calls this out.
EDIT: It does https://spec.graphql.org/October2021/#sec-Objects. What you have here @argoyle is valid GraphQL. I can modify the getter generation logic for this scenario.
One last note: this should have been more prominent in the release notes because it is a breaking change. Also probably should have justified a minor version bump.
Thanks! I cut an interim release v0.17.15 that includes the latest refinement, and by the time you get a config option landed I can then cut a v0.17.16. I’m going to leave this issue open until then.
I asked some co-workers the same question and they added these:
Not at all:
Is{UnionName}()
signpost functions leverage the Go compiler to help alleviate some of the confusion hereID: ID!
input
types if you need structured input to a query or mutationinput
types can’t be used as returns, solely as inputsInt!
, where Go only has pointersThat’s what I have off the top of my head. I haven’t done anything too terribly exotic with gqlgen though (other than filling in schema.resolvers.go, it’s just using whatever gqlgen generates), so I’m sure others have stumbled on bigger footguns.
@MichaelMure I re-opened this issue because it looks like there may be some more rough edges to iron out.
If we can’t easily make the new generating getters for interfaces transparently painless for existing users, I’d like to default it to off and make a config option to allow people to opt-in to this new behavior while we continue to refine it. What do you think of that @neptoess ?