Slide 36
Slide 36 text
N + 1問題
● @SchemaMapping は Corporation 一つ一つを解決する時に呼び出される
● GraphQL に 複数の Corporation を返すAPIがあると何度も呼び出されてしまう
○ DBアクセスや他サービスの呼び出しがN回実行されてしまう
コード
@Controller
class CorporationController () {
@QueryMapping
fun corporations(): List? =
listOf(
Corporation(id = “1”, … , offices = null),
Corporation(id = “2”, … , offices = null),
Corporation(id = “3”, … , offices = null),
…
))
@SchemaMapping
fun offices(corporation: Corporation): List =
map[corporation.id]
val map = mapOf(
“1” to listOf(Office(id = “1”), Office(id = “2”)),
“2” to listOf(Office(id = “3”)),
“3” to listOf(Office(id = “4”), Office(id = “5”)),
…
)
}
© SMS Co.,Ltd.