-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Support GetMany federated entities in entity resolvers #1686
Comments
Thanks for writing this up. If you already have something working it would help visualise this.
This interface is pretty weakly typed. If you know all the keys for the entity why not generate something like:
Do you mean heterogeneous on the return type? I can definitely see uses for this when multiple types share the same id / table, eg a chat event that could be many concrete types, though I'm not sure if I have a concrete example where the id is known but the type isnt. Is this a micro optimisation? We also want to roll dataloaden into the core execution engine at some point, so we can avoid timeout based dispatch. The interfaces required by that would be very similar to this, theres probably a bit of crossover. |
@vektah thanks for taking a look! Apologies in advance for repeating stuff you already know, Im just covering as much context as I can for a more complete conversation.
Yeah that is absolutely preferable and definitely the API I'm after as well. I didn't find an easy way to generate anonymous structs because entity resolvers are derived from the generated
Yeah that's my bad. What I mean is that representations can be heterogeneous, so the federation runtime needs to call the corresponding entity resolvers with the list of representations for the correct
Definitely in principle there is crossover because in the end entity resolvers are just resolvers, and ideally they would have the same signature. Tho I haven't wrapped by head around all the nuances of implementing this for regular field resolvers as well, this has definitely been in my radar because at KA we have several places where field resolvers have dataloaders to address the same fundamental issue. So Im all for also solving for this as well. Besides perhaps sharing code for generating the structs for the resolvers and ensuring a consistent resolver signature, Im not entirely how much entity resolvers and field resolvers can share right now. But if you have more specific details, I'd love to hear them and discuss them.
|
I will push up my changes to a branch sometime today to have a more concrete space to talk about implementation details. |
It looks like this is solved, right? Can we close this? |
What happened?
Currently, federated entity resolution is done in go routines, and resolution is 1 entity at a time but in parallel. This optimization works well! But it requires the use of dataloader/batchloader sort of abstraction in order to be able to then process these entities together in client code, which adds complexity in both logic and often tests.
At Khan Academy, for example, we have a lot of places where we need to:
What did you expect?
Entity resolvers are provided the entire list of representations that need to be resolver upfront.
Minimal graphql.schema and models to reproduce
It would be quite helpful to get a list of representations up front to avoid the need for dataloader/batchloader type of abstraction entirely. And ideally, any approach here would be opt-in.
There are multiple ways to tackle this, and I list a couple below. But I'm sure there are others yall can think of and I would love to hear them.
exec.go
can create the correcttype Entity interface
in Go. In order to support this, we would need to add another interface to plugins that get called right around heregqlgen/api/generate.go
Line 76 in 59a3091
Data
so that it can do extra processing before callingcodegen.GenerateCode
.@entityResolver
where we can specify right in the schema if a particular entity resolver supports a list of representations. This one is the more straightforward approach I found, and I have a working set of code changes.Some of the complexities are (unless stated, these have been sorted out in a working implementation):
versions
If there is interest in something like this, I'm happy to push up to a branch the changes to support option 2 above. Or explore other ideas as well! But roughly, client-side code is more or less like this right now:
schema.graphql
Entity resolver
The text was updated successfully, but these errors were encountered: