Brian Dilley
03/25/2021, 8:49 PMdata class Movie(
val id: Long,
val token: String
)
data class User(
val id: Long,
val name: String
) {
fun movies(userIds: List<Long>): List<Movie> {
return LongRange(0, 2)
.map { Movie(it, "movie-$it") }
.toList()
}
}
@Component
class UserQueries : Query {
fun users(): List<User> {
return LongRange(0, 5)
.map { User(it, "user-$it") }
.toList()
}
}
In a database situation it would be really bad to query users along with their movies because it would issue a single query per user to get their movies. Is there a way to avoid the multiple queries and instead get a list of the user ids and make a single query for all of their movies?Shane Myrick
03/25/2021, 8:57 PMn+1
problem in graphql. There are many different solutions.
First off is that you can have your movie service handle batch requests and you don’t send the request until you have resolved all the users.
Of course you could also implement caching in the downstream services.
But if you wanted GraphQL caching, you can use the Data Loader pattern: https://expediagroup.github.io/graphql-kotlin/docs/server/data-loadersBrian Dilley
03/25/2021, 9:00 PMDariusz Kuc
03/25/2021, 9:30 PMBrian Dilley
03/25/2021, 9:32 PM