graphql-go / graphql

An implementation of GraphQL for Go / Golang
MIT License
9.87k stars 839 forks source link

Array elements are being resolved in series instead of parallel? #592

Closed AttilaTheFun closed 3 years ago

AttilaTheFun commented 3 years ago

I've been using this library for a while, but I just got around to setting up open tracing for it. While looking at some of the traces, I noticed what appears to be serial resolution of fields on array elements.

This is a screenshot from a trace where I fetched my inbox which had 12 threads. As you can see, the display data field appears to be resolved in series for threads 0...11.

Screen Shot 2021-01-12 at 10 37 08 PM

What I would expect is that these resolvers would run in parallel, and would only block if they hit a dataloader. From this PR I assumed that resolution was supposed to be async-by-default. https://github.com/graphql-go/graphql/pull/388

Is this by design? Or am I holding it wrong? I'm happy to provide more information but I'm not sure what would be helpful.

AttilaTheFun commented 3 years ago

Ah I think I might know what's wrong - I just looked at the concurrent resolvers example and saw that the resolvers there return thunks. I think I need to update my resolvers to return functions if I want them to be async. I thought all of the resolvers were executed concurrently (at the same field level) by default. I'll try that and close this issue if it is resolved.

AttilaTheFun commented 3 years ago

Yeah that was the issue - I had to return a thunk in order to get that to work asynchronously.