-
Notifications
You must be signed in to change notification settings - Fork 77
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
Using a dataloader inside resolve_reference
does not work
#205
Comments
Hey @col, should have documented the other issue better, a little hazy now. I believe I didn't actually find a direct solution to the problem, it just wasn't a problem anymore on the project that's using it. Had a window to take a look but couldn't get the example to run. I 'd take a look at |
I think this basically boils down the the difference between GraphQL-Batch and Dataloader:
So inside a To address this, I can think of a couple possibilities:
There might also be a way to call dataloader methods like What do you think of those approaches? |
Thanks for your input @rmosolgo! I've been trying to get this to work using append_job but have been unsuccessful. Both the approaches you've suggested sound like they'd work. Option 1 - resolve_references Option 2 - return data loader requests @daemonsy Let me know what you think. I'm happy to put a PR together for Option 1 sometime next week. |
Apologies from the late reply, just returned from a holiday in Singapore :) Hey @rmosolgo it's been a while, hope you're doing well. Thanks for the clear explanation, that rang a big bell. I've personally bumped into surprises with pausing execution. @col I'm going to do a spike on the suggestions on our codebase. One consideration is that we've kept to an implicit convention keeping it close to Apollo's reference implementation to avoid creating new concepts/APIs. |
Hey @daemonsy, live in Singapore, I could have taken you out for a drink! Maybe next time! Anyway, I'd still be very happy to see a better solution for this that keeps the original API intact. I had tried a few things but none of the approaches I tried worked. I'm wondering if it would be better to lazily resolve the references while resolving the the Entity type rather than trying to do it as a loop in _entities. This would fit better into the existing DataLoader pattern and allow all the Entity resolvers to be paused until the data it fetched. Just a thought. |
Hey @col 😱 definitely my loss. I'm from Singapore but reside in NY with my family. It was good to be back home for a while, despite the weather :)
Do you have an example or pseudo code for how this might look? |
I'd suggest we close this issue at this point. I wasn't able to find a fix that didn't require adding the |
What makes it slightly tricky is if you support multiple keys, for example, With the 2nd option proposed by @rmosolgo, you can let dataloader handle the batching by using |
It's important that when a subgraph service receives an
_entities
query from the gateway that it can resolve all of the references efficiently. You would expect that using a data loader inside theresolve_reference
method for each entity would achieve this but unfortunately it does not work as expected. Currently the data loader is being invoked for each individual reference rather than as a single batch.I've created a small example application here: https://github.com/col/apollo-federation-example
Expected Output:
Actual Output:
At scale this becomes a significant problem as we can receive hundreds of references in a single
_entities
query.The text was updated successfully, but these errors were encountered: