Skip to content

How to implement data fetching logic in suspended function with Spring Webflux? #971

Answered by dariuszkuc
Infergo asked this question in General
Discussion options

You must be logged in to vote

Hello 👋
There are number of ways this can implemented. If you are using latest graphql-kotlin-spring-server i.e. 4.x (currently alpha) release we default to use SpringDataFetcher that allows you to autowire Spring beans to method arguments.

@Component
class UserQueryController(private val userRepository: UserRepository) : Query {
    suspend fun user(keycloakId: String): UserClassSchema {
        return userRepository.findByKeycloakId(keycloakId)
            .map { u ->
                UserClassSchema(
                    id = u.id!!,
                    keycloakId = u.keycloakId,
                    email = u.email,
                    firstName = u.firstName,
                    lastName =

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@smyrick
Comment options

Answer selected by Infergo
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants