How to skip generation of entity resolvers for extended types #1944
Replies: 8 comments
-
My memory is a little rusty, but if there no extra fields why are you "extending" the type in the first place? :) Maybe we can make the error messaging a little better by checking if all fields are external and erroring out if you have "@extends" |
Beta Was this translation helpful? Give feedback.
-
The issue, as I understand it, is this: I am defining my own type that has a field of type Foo, which is defined somewhere else. Because Foo is defined somewhere else, my resolve_foo() only needs to return a "stub" Foo that defines the @key-fields for a Foo. In the example for this issue, it would be something like
But gqlgen obviously can't compile that code because it doesn't know about the So the question is: what is the right way to do something like this, if not to do this "empty @extends"? There's probably a right way that we just don't know about. |
Beta Was this translation helpful? Give feedback.
-
Hmmm yeah sorry I wasn't more specific here. As Craig said this is a type that is defined in a different service. Service A
Service B, which would like to be able to add
In this sort of setup, Service B is currently required to provide an entity resolver for In this contrived example, that's not a real big deal. But we have an interface with lots of implementing types so each one of those types currently needs an entity resolver. Let me know if it would help to setup a sample repo. |
Beta Was this translation helpful? Give feedback.
-
I think the right fix is that if a type is extended, and all the listed fields are |
Beta Was this translation helpful? Give feedback.
-
Yeah, I think the spec is a bit unclear on this point. If I understand correctly, if a type has only |
Beta Was this translation helpful? Give feedback.
-
While writing about the spec issues, I realized it's possible we could fix this entirely in gqlgen. It would be a little ugly, but we'd just have to make the server not generate these methods, and instead if it gets a query for some type that doesn't have a method, it can just handle it some special way. (The only fields that could legitimately be requested are those passed, anyway.) But then again, it's not actually stated in the spec that we can never be asked for an |
Beta Was this translation helpful? Give feedback.
-
This led me to figure out what Apollo does in this situation. I've described it in the Apollo issue. It's basically what I proposed in the previous comment: the server just sort of does what it can since there's no application logic for this. |
Beta Was this translation helpful? Give feedback.
-
What happened?
I'd need to add an entity resolver
FindFooByID
.What did you expect?
No entity resolvers being needed for extended that only have external fields. Is this something we can optimize in gqlgen so that entity resolvers for extended type with only external fields arent needed? Or would that be some sort of violation of the spec?
Minimal graphql.schema and models to reproduce
versions
gqlgen version
? 0.11go version
? 1.13.8 darwin/amd64Beta Was this translation helpful? Give feedback.
All reactions