Hey all, we’re using Spring Boot + GraphQL Kotlin ...
# graphql-kotlin
s
Hey all, we’re using Spring Boot + GraphQL Kotlin and had a question related to batching / N + 1 problem that we are currently using data loaders for (we don’t use it for caching). I’ve been reading through some of the works related to this in recent PRs, GitHub issues, etc. and it seems like there is another pattern floating around that solves this without the use of data loaders and was hoping someone could fill the gaps in. I have this simplified use case:
Copy code
class Shape(val primaryIds: List<String>, val secondaryIds: List<String>, val tertiaryIds: List<String>) { // ids fetched from first DB call
  lateinit var primaryColors: List<Color> // colors fetched from subsequent DB call
  lateinit var secondaryColors: List<Color> // could be `fun` instead
  lateinit var tertiaryColors: List<Color>
}
and a
ColorService
bean that does the data fetching:
Copy code
fun getColors(ids: List<String>): List<Colors> { ... }
What would be the pattern here? Do we pass in an instance of
ColorService
during the construction of `Shape`s so now that batching is a service level concern? How would the service batch the three calls coming from primary, secondary, and tertiary?