https://kotlinlang.org logo
#graphql-kotlin
Title
# graphql-kotlin
a

asavio

09/19/2023, 7:28 AM
I watched

this

amazing talk on ktor graphql from KotlinConf’23, Amsterdam yesterday. Amazing talk! I’m now curious about how ktor and kotlin graphql solves the n+1 problem that we generally encounter in graphql servers. I couldn’t find any resources on how ktor solves that. Does any one know how that’s done in ktor? Thanks.
d

Dariusz Kuc

09/19/2023, 2:55 PM
👋 folks generally use data loader pattern to batch requests downstream (see https://opensource.expediagroup.com/graphql-kotlin/docs/server/data-loader/#dataloaders-and-coroutines)
a

asavio

09/23/2023, 1:10 PM
Oh, this is great. Thanks, will check it out!
g

Gerard Klijs

09/25/2023, 11:59 AM

This

presentation about data loader 3.0 might also be interesting.
d

Dariusz Kuc

09/25/2023, 12:40 PM
I watched it expecting some fundamental rewrite.... but it was nothing new
graphql-java
resolves queries in a breadth first matter (afaik all graphql libs do) - it will gather all available futures (for given level) and then await for the first leaf value. It actually even does an extra optimization by checking for sync leafs - so it will actually traverse far down the tree until all fields are futures before waiting for them. This is actually what Sam implemented with sync exhaustion strategy for the batch dataloader.
As for federated resolver -> thats what the query plans are for (so using Apollo router you end up with 4 fetches and definitely dont use thread per id)... so again nothing new on that front 🤷
I did like the will it compose game though :)
2 Views