Description
Add Kotlin Coroutines specific support.
Kotlin Coroutines support as alternative type of the CompletableFuture
in DataLoader
Similar to the existing ReactorDataLoader(internal class in the Spring GraphQl) etc.
- Create
CoroutinesBatchLoader
andCoroutinesMappedBatchLoader
variants. - Create a Kotlin Coroutines variant of DataLoader.
All Controller(Data Fetchers) fun supports Kotlin Coroutines
Currently I encountered an issue when returning a Flow
in a query data fetching. For example,
Define the following Graphql schema.
type Query {
allPosts: [Post!]!
}
When executing the following query.
@QueryMapping
fun allPosts(): Flow<Post> = postService.allPosts()
I got the exception like this.
error message: Can't resolve value (/allPosts) : type mismatch error, expected type LIST
Reproducing the issue: https://github.com/hantsy/spring-graphql-sample/blob/master/spring-graphql-rsocket-kotlin-co
Support Flow as Subscription return type
In a Kotlin Coroutines project, I would like use a Flow instead of Flux/Publisher as Subscription return type, that make my codes look smooth, no mixes of Reactor API and Kotlin Coroutines API.
val flow=MutableSharedFlow<Event>()
//emit event
flow.emit(event)
//subscribe in a Subscription
fun onEventOccured() = flow (instead of a Flux/Publisher)
Currently I have to convert it back to a Reactor Flux to make it work.
override fun commentAdded(): Flux<Comment> = flow.asFlux()
The example codes: https://github.com/hantsy/spring-graphql-sample/blob/master/spring-graphql-rsocket-kotlin-co/src/main/kotlin/com/example/demo/Services.kt#L92
Spring GraphQl has built-in ReactorBatchLoader
internally. I think it is possible to use the same approach to get Flow
support as a Subscription type.
Kotlin Coroutine variant of DataFetcherExceptionResolver
Provides a variant to return suspend
or Flow
instead of the Reactor APIs.