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
I've been trying to write out some asynchronous resolvers for one of our services and have been running into issues with a specific requirement. To explain the problem consider the scenario:
I have a top level query that accepts an input.
@DgsData() fun query account(id: String): CompletableFuture<Account>
I have a nested resolver that also depends on the ID input from the parent and there is no requirement for these to be sequential.
@DgsData(parentType = "Account") fun query profile(): CompletableFuture<Profile>
Normally the suggestion is to either call getSource() which is a blocking call and not a viable solution for our use case, or to pass the ID down via setting the localContext. However, this runs into issues when we want both resolvers to be asynchronous and it seems like graphql java doesn't support wrapping a CompletableFuture in a DataFetcherResult like so:
fun query account(id: String): DataFetcherResult<CompetableFuture<Account>> // will not resolve Account properly in result
Alternatively, wrapping it the other way CompletableFuture<DataFetcherResult> also won't allow you to access the localContext until the future is resolved, making it also blocking.
It doesn't make sense to me that a context I'm setting synchronously would be blocked by the asynchronous result and there should be some support for this when building nested resolvers. I'll also note that ideally there would also be support for having parent input context available to the nested resolvers by default.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I've been trying to write out some asynchronous resolvers for one of our services and have been running into issues with a specific requirement. To explain the problem consider the scenario:
I have a top level query that accepts an input.
@DgsData() fun query account(id: String): CompletableFuture<Account>
I have a nested resolver that also depends on the ID input from the parent and there is no requirement for these to be sequential.
@DgsData(parentType = "Account") fun query profile(): CompletableFuture<Profile>
Normally the suggestion is to either call getSource() which is a blocking call and not a viable solution for our use case, or to pass the ID down via setting the localContext. However, this runs into issues when we want both resolvers to be asynchronous and it seems like graphql java doesn't support wrapping a CompletableFuture in a DataFetcherResult like so:
fun query account(id: String): DataFetcherResult<CompetableFuture<Account>> // will not resolve Account properly in result
Alternatively, wrapping it the other way CompletableFuture<DataFetcherResult> also won't allow you to access the localContext until the future is resolved, making it also blocking.
It doesn't make sense to me that a context I'm setting synchronously would be blocked by the asynchronous result and there should be some support for this when building nested resolvers. I'll also note that ideally there would also be support for having parent input context available to the nested resolvers by default.
Beta Was this translation helpful? Give feedback.
All reactions