You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Kotlin coroutine suspend fun resolver hangs when awaiting a data loader #419
However it seems to be hanging on the await. I think it's blocking there, before java-graphql called the dispatch on the registered data loaders (in DataLoaderRegistry).
What would be the best way to solve this? I couldn't really find examples in the documentation or the original pull request (#201)
I think the problem is that you're wrapping the CompletionStage provided by the DataLoader API with the coroutine's CompletableFuture representation created by graphql-java-tools. As you've pointed out already, this disconnects graphql-java from your dataloader, and so it is unable to dispatch it.
My understanding is that .loadMany will not actually call your data loader method directly - it'll only create a "request to fetch these users at some point", which you need to return in your data fetcher so that graphql-java can orchestrate when to actually call the data loader (maybe there'll be more data fetchers making use of the same data loader - then all those keys will be aggregated by graphql-java and the data loader will only be called once, when graphql-java sees fit).
I haven't worked with dataloader + graphql-java-tools yet, but I think you need something like this
funloadUsers(env:DataFetchingEnvironment): Any {
returnContext.getDataLoaders(env)
.usersLoader
.loadMany(listOf(1, 2, 3))
}
Any updates for that issue? I'm facing the same problem now.
Here was discussion connected with dataFetcher link
The easiest solution is calling dispatch every time but it not the right choice.
suspendfunloadUsers(env:DataFetchingEnvironment): List<UserGQL> {
val dataLoader =Context.getDataLoaders(env).usersLoader
val users = dataLoader
.loadMany(listOf(1, 2, 3))
dataLoader.dispatch()
return users.await().map { UserGQL(it) }
}
Activity
arian commentedon Aug 4, 2020
Might it be because this example in the graphql-java docs: https://www.graphql-java.com/documentation/v15/batching/
and with
MethodFieldResolver.kt:190environment.coroutineScope().future(options.coroutineContextProvider.provide()) { invokeSuspend(source, resolverMethod, args)?.transformWithGenericWrapper(environment) }it might be equivalent to the
supplyAsyncexample the docs tells us not to do?williamboman-pp commentedon Sep 26, 2020
I think the problem is that you're wrapping the CompletionStage provided by the DataLoader API with the coroutine's CompletableFuture representation created by graphql-java-tools. As you've pointed out already, this disconnects graphql-java from your dataloader, and so it is unable to dispatch it.
My understanding is that
.loadManywill not actually call your data loader method directly - it'll only create a "request to fetch these users at some point", which you need to return in your data fetcher so that graphql-java can orchestrate when to actually call the data loader (maybe there'll be more data fetchers making use of the same data loader - then all those keys will be aggregated by graphql-java and the data loader will only be called once, when graphql-java sees fit).I haven't worked with dataloader + graphql-java-tools yet, but I think you need something like this
Nokinori commentedon Dec 19, 2020
Any updates for that issue? I'm facing the same problem now.
Here was discussion connected with dataFetcher link
The easiest solution is calling dispatch every time but it not the right choice.
So what is the best option to solve this?