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

Rupesh

05/27/2021, 2:45 AM
Hi, I wanted to understand how apollo GQL plugin works for android and iOS. Do they share the same codebase for generating the platform specific code? I wanted to build something which generate the code for both the platform at compile time. Any leads would be appreciated. Is there anyway to achieve the same thing by sharing the common codebase?
s

Shane Myrick

05/27/2021, 3:57 AM
#apollo-android may be better for getting more details. I know the code bases are separate but they do support Kotlin Native in the android client, which could help generate sharable code
r

Rupesh

05/27/2021, 4:08 AM
@Shane Myrick Thanks. I'll check that how to use Kotlin Native sharable code.
I just found out GraphQL-Kotlin and you are one of the contributor of the repo. Could you please give me some more details. I know how to build
gradle-plugin
. I just want to understand how to reuse the same codebase for
iOS
s

Shane Myrick

05/27/2021, 5:11 AM
We currently do not support Kotlin Native/Multiplatform for our client. That support is being tracked here: https://github.com/ExpediaGroup/graphql-kotlin/issues/876
j

Jilles van Gurp

05/27/2021, 9:17 AM
I created that ticket last year. By now we have our own client generation. @Nikky who works with me left a comment on on the ticket recently with some details on that. We also shifted our focus from android to kotlin-js as we are mainly focusing on that for UI now (we use fritz2). We still use the expedia graphql framework, which has improved enormously over the last few months. Kotlinx serialization is definitely the way to go for serializing. The hard part is generating functions stubs for graphql queries. Especially when mostly you just want the client equivalents of the exact functions you are exposing on the server side. IMHO, a compiler plugin might actually be the way ultimately. That would allow full use of reflection during the code generation phase without requiring that at run time. Mostly the rest of the code can use things like ktor client, kotlinx-serialization, etc. Minus the code generation, that's pretty much what we do internally. There's a bit more ceremony to creating client stubs than I like but not a whole lot.
n

Nikky

05/27/2021, 9:29 AM
note that we share serializable data classes between expedia-graphql-backend and the multiplatform-graphql-client and do not generate new classes from the sdl or such we have 3 modules:
server
mp-client
and
mp-data
and have quite a few things synced up manually ideally what i would like to see .. is adding a new query/mutation on the
server
using serializable classes from
data
would generate a Query/Mutatation that uses the same serializable in
mp-client
but plugin setups that span multiple modules sound reallly hard.. so maybe the same is doable using multiple common sourceSets in a
kotlin("multiplatform")
project but that forcefully merges client and server code and makes the sourcesets rather messy...
4 Views