I did find apollo support on Ktor, does anyone how...
# apollo-kotlin
j
I did find apollo support on Ktor, does anyone how to make queries in it? I cant find anything in documentation: https://apollographql.github.io/apollo-kotlin-ktor-support/kdoc/index.html Or is it better run regular Apollo for this?
b
Apollo Kotlin uses OkHttp by default, but if you want it to use Ktor instead, you can add this optional library. The documentation for it is here: https://apollographql.github.io/apollo-kotlin-ktor-support/welcome.html Once the setup is done you can use Apollo Kotlin as usual.
j
Ah okej sorry misunderstood the use case, so its only the http level under the hood. Is it large difference of ktor vs okhttp? I am using Ktor server + Ktor client for other things now. I guess for transitive deps and binary size advantage then using Ktor for Apollo as well or?
b
Yes I think the main advantage would be the binary size, but also being able to reuse some configuration of the client (e.g. Auth) if you need that. If size is a concern, don't forget to exclude the OkHttp transitive dependency in your Gradle build.
j
Ugh so I need to manually exclude it if using Ktor variant? Binary size not neccessary a problem, but its nice to reduce it if can. Nice to avoid having like 3 different http clients mixing GraphQL and REST in different contexts in server and client in monorepo πŸ˜„ I am trying to re-use things between server and client side gradle modules as well where its possible. I am also using the Apollo execution plugin, so feels like bleeding edge this setup πŸ˜„
To be honest I am still uncertain when I should use GraphQL or not, pros and cons with it. But for my use case I think its quite nice, hopefully the gradle task of download graphql scheme still working on KMP.
b
That should still work yes 😊
j
Sweet, looking forward to have my first full stack in Kotlin with all platforms supported in one place, all platforms except TV at the moment. Full stack is in iOS, Web, Desktop, Android blend with server API in same mono repo and stack with Kotlin multiplatform. So nice I can do all of this so easy in Kotlin. This would be painful to do with other things like JS and NodeJS πŸ˜„
πŸš€ 1
b
Wow that sounds good! K
j
Yeah much easier than React Native or Flutter used in the past, as can mixing native + CMP features in parallell and re-use a lot of libraries like Apollo, Kotlinx and such between server and client in one place. Even OAuth stuff like Google OAuth is nice to share πŸ™‚ Ah well, not need to marketing it, but nice to try it and it actually works sweet where can use native Android and iOS libs when I need or want, but dont have to.
πŸ‘ 1
m
Having okhttp as a forced dependency isn't great now that KMP is getting traction but it's one of those things that is going to be hard to undo.
A tracking issue could be useful though
(FWIW, I don't think it's such a big issue because R8 will most likely be able to remove all that bycode. Worst case, you can explicitely ignore it indeed)
j
Yeah I like how Retrofit solved this, easy to replace stuff if I recall correctly. But yeah there is no nice way of dealing with transitive deps in Gralde imo, would be nice if Gradle could automatic reolsve what code actually used and not add into classpath at all, and not let R8 rip it away πŸ˜„ Also we dont have R8 in iOS right, or is it applied in that as well when build IOS binaries for KMP libs?
m
There is no okhttp for iOS so there is no problem
By default Apollo uses the system APIs there (NSUrlSession)
j
Ah right forgot πŸ˜„