KGraphQL
KGraphQL copied to clipboard
Implement a DataLoaderDSL for batching
Implement DataLoader style.
I've been thinking about a structure like this:
...
data class Tree(val id: String, val parentId: String?)
...
type<Tree> {
// String - defines the key that will be sent from the [prepare] into [loader]
// List<Tree> - defines the return type that the [loader] is required to return.
// the loader is then required to return it in a map format like Map<String, List<Tree>>
dataProperty<String, List<Tree>>("children") {
// Step 2: This will only be called once.
loader { keys: List<String> ->
keys.map{ id -> id to listOf(Tree("SomeId", id)) }.toMap()
}
// Step 1: This will be called for each node in the list, or only once if it's not a list
prepare { parent: Tree -> parent.id }
}
}
Anyone is welcome with some input on how this could be achieved.