nuwave / lighthouse

A framework for serving GraphQL from Laravel
https://lighthouse-php.com
MIT License
3.36k stars 437 forks source link

Async Batched Queries #1918

Open tlaverdure opened 3 years ago

tlaverdure commented 3 years ago

What problem does this feature proposal attempt to solve?

It looks like webonyx/graphql-php can fetch data asynchronously. https://webonyx.github.io/graphql-php/data-fetching/#async-php

I'm not sure if batched queries are currently executed synchronously or asynchronously, but I could imagine there would be great performance benefits if they were resolved asynchronously. @spawnia could you confirm? It looks like you have been working on the ReactPromiseAdapter recently and I'm not sure if that is related. 👀

https://github.com/webonyx/graphql-php/commits/master/src/Executor/Promise/Adapter/ReactPromiseAdapter.php

Which possible solutions should be considered?

I assume we could allow an alternate path for execution here if we wanted to use promiseToExecute(): https://github.com/nuwave/lighthouse/blob/985d39e4c0a513453e964bb1e04a97252d8e9665/src/GraphQL.php#L159-L165

And I'm also naively assuming that it should just work but let me know what you think.

spawnia commented 3 years ago

I am all over the graphql-php codebase, mostly working on strict typing and uncovering/fixing bugs. Have not paid particular attention to async execution.

Your assumption seems sound, I think it is very much possible and useful for Lighthouse to allow alternative executors. Open for pull requests 😉

tlaverdure commented 3 years ago

Cool, I'll dig in once I find some time. Thanks for the feedback.

bingalls commented 3 years ago

async php & react php are converging; you might want to implement this in php v8.1 fibers

mathiasmoser commented 2 years ago

i think async execution would be a great improvement for lighthouse. perhaps laravel octane could help to reach that behaviour

JeroenJochems commented 1 year ago

@mathiasmoser how would laravel octane help with this?