#Are ResolveField fetched sequentially?

18 messages · Page 1 of 1 (latest)

soft walrus
#

Does anyone know? It feels that way from fetching sub fields it adds to latency.
Can it be done in parallel?

lunar moat
#

Node.js is single-threaded, so you really can't do anything in parallel. You could implement DataLoader and fetch multiple results at once.

GitHub

DataLoader is a generic utility to be used as part of your application's data fetching layer to provide a consistent API over various backends and reduce requests to those backends via batc...

soft walrus
#

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

lunar moat
soft walrus
#

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

soft walrus
#

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

lunar moat
#

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.

soft walrus
#

I'm doing this with Insomnia to send graphql queries

lunar moat
soft walrus
#

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

maiden quiver
#

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...

â–¶ Play video
#

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