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

DataLoader::await resolves all loaders #60

Open
piotrkreft opened this issue May 18, 2022 · 0 comments
Open

DataLoader::await resolves all loaders #60

piotrkreft opened this issue May 18, 2022 · 0 comments

Comments

@piotrkreft
Copy link

Hi,
great job on the lib guys! It really does bring cool possibilities to PHP-driven apps :)

Quite recently I started to look into possibilities to introduce DataLoader to a new kind of API introduced into my project. Whilst it fits really cool for the use case it does have one downside which I managed to resolve but perhaps it could be a good addition to the lib in general.

In the project, I do have a couple of independently sourced loaders for different kinds of data - all of the loaders besides one return promises being resolved on the serialization/normalization process of the API response - and it generates a great result. Code is clean and the amount of backend/database roundtrips is significantly reduced.
However, since I do have to resolve one loader's data in the runtime of generation of the response I use the DataLoaderInterface::await method - and the issue is that it resolves ALL the promises from all of the loaders. It's understandable of course that the method exists and it works how it does but in this very case instead of having x(amount of loaders - 1) + y(unique runtime resolutions) I end up with x*y roundtrips.

As a workaround, I prepared a new extending interface implementing the non-static awaitSingle method. In the implementation instead of using Overblog\DataLoader\Promise\Adapter\Webonyx\GraphQL\SyncPromiseAdapter I use GraphQL\Executor\Promise\Adapter\SyncPromiseAdapter allowing to resolve only specific loader.

Any thoughts on the topic? I could give it a try and prepare the appropriate implementation if this would sound like something you'd like to have in the solution :)

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

1 participant