#Are ResolveField fetched sequentially?
18 messages · Page 1 of 1 (latest)
Node.js is single-threaded, so you really can't do anything in parallel. You could implement DataLoader and fetch multiple results at once.
but async allows to do concurrently
I have a resolver where if I query sub objects latency just adds up
and we use prisma it does what dataloader do
Well, concurrently still means they add up: https://tsh.io/blog/simple-guide-concurrency-node-js/
that's the point, it's sync instead of async. If I add a delay function in a ResolveField. It waits for that ResolveField to be done to call the other ResolveFields
if I add a delay to a resolveField of 5 seconds to a query that takes 1 second the graphql takes 6 seconds instead of around 5 seconds
Oh, I see. Have you tried with vanilla apollo/mercurius server? I'm don't have deep knowledge of how Nest integrates the drivers. It would be good to know whether it's Nest issue, or the problem comes from the driver (or even graphql.js).
If I remember correctly, the graphql specs don't guarantee that the field are resolved in the requested order, so it probably should work like you expect.
I'm doing this with Insomnia to send graphql queries
This sounds correct though. The top level query has to resolve first, before the fields on that object can begin resolving.
If you have:
- query that takes 1s
- field A resolver that takes 2s
- field B resolver that takes 2s
it should be around 3s, at least that's what I'd expect.
In this example I have a model where we query properties +- 200 ms and adding 5 sub models looks like additive as latency increase for each model added
https://youtu.be/cCOL7MC4Pl0?si=QrqY0-5W7qjJ_X6o this is a good video on how the event loop works
"In The Loop" presented by Jake Archibald at JSConf.Asia 2018
Have you ever had a bug where things were happening in the wrong order, or particular style changes were being ignored? Ever fixed that bug by wrapping a section of code in a setTimeout? Ever found that fix to be unreliable, and played around with the timeout number until it kinda al...
oh wait that is for the browser
maybe this will cut it then
it is really mind bending sometimes on what is when processed and why
difference in microtask and promise queue and such