Skip to content

DataLoaders in Spring #1533

Answered by samuelAndalon
hantsy asked this question in Q&A
Sep 1, 2022 · 4 comments · 9 replies
Discussion options

You must be logged in to vote

You need very careful about the async thread model as graphql-java async model is CompletableFuture, if your source uses suspendable functions you cannot just interop the suspend function with a future, instead you need to run the suspend fn in a coroutine scope and use Deferred -- please check https://github.com/samuelAndalon/graphql-kotlin-batching-demo/blob/batching-showcase/src/main/kotlin/com/example/demo/DataLoaderConfiguration.kt#L47

that way you can get a Deferred Object and then you interop the Deferred with a CompletableFuture

TLTR; you are wrong here

override fun getDataLoader(): DataLoader<UUID, Author> {
        return DataLoaderFactory.newDataLoader { keys, environment ->

Replies: 4 comments 9 replies

Comment options

You must be logged in to vote
7 replies
@hantsy
Comment options

@hantsy
Comment options

@samuelAndalon
Comment options

@hantsy
Comment options

@samuelAndalon
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by samuelAndalon
Comment options

You must be logged in to vote
2 replies
@dariuszkuc
Comment options

@hantsy
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants