Skip to content

with spring boot, lateinit on nullable type #897

Answered by dariuszkuc
zzazang asked this question in Q&A
Discussion options

You must be logged in to vote

Disclaimer: I'm not an expert on dataloader as I haven't used it but below should work.

Instead of a lateinit property which as you mentioned cannot be null, you should be able to expose nullable GraphQL field through a function that accepts the DataFetchingEnvironment and use that to access the dataloader, e.g.

fun foo(id: Int, environment: DataFetchingEnvironment): CompletableFuture<String?> {
  return environment.getDataLoader<Int, String?>("myDataLoader")
      .load(id)
}

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by smyrick
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
Category
Q&A
Labels
None yet
3 participants
Converted from issue

This discussion was converted from issue #897 on October 17, 2020 04:46.