Hi, I wanted to understand how apollo GQL plugin w...
# apollo-kotlin
r
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?
f
The plugin is not platform dependant. You can use it to generate common Kotlin code so it can be used from both iOS and JVM targets.
It's just Gradle (maybe Maven) dependant
r
Could you please share sample or any documentation to start with? If you have any.
m
You can also look at this project which is a more complete example: https://github.com/joreilly/MortyComposeKMM/blob/main/shared/build.gradle.kts
r
Actually I am looking something which can generate code at compile time/build time.
m
It does! 🙂
The Gradle plugin will generate multiplatform code that's working for both iOS and Android based on your .graphql files
r
So what I understood is that plugin will generate the code for
shared-module
which can be used for both the platforms. It can be run from Android Studio. Can I run the plugin task from xCode too?
m
plugin will generate the code for 
shared-module
 which can be used for both the platforms
Correct. You don't have to name your module
shared-module
though, you can use any name you want.
Can I run the plugin task from xCode too?
Not really, the plugin is a Gradle plugin and Xcode doesn't support Gradle. In all cases, it generates Kotlin code, which Xcode cannot compile. You can use a
packForXcode
task to create a
.framework
file exported to XCode. See https://github.com/joreilly/MortyComposeKMM/blob/main/shared/build.gradle.kts#L72 for an example
r
Here both the codebase is not from KMM will I still be able to add/create that on existing codebase which were not created as KMM project ?
f
So you have two projects, Android app and iOS app? If that's the case, add a multiplatform module to your Android project with Android and iOS targets. For each change, you will have to pack the common code for your iOS app as a dependency like Martin said.
r
If the iOS devs wants to generate the code. How will it be possible. As @mbonnin mentioned its not possible from android. How both the team can work independently without dependent to each-other. As Android Studio supports gradle it will be easier for the android to run the plugin task and get the code.
f
I think the only way right now is to use AppCode from JetBrains which can handle both Kotlin and Swift (and Gradle)
âž• 1
Or the iOS can download Android Studio and work on common code from that and switch to XCode to do iOS stuff
r
Thanks @Filip Wiesner. Understood.
r
You can use the cocoapods integration. As long as iOS users have Gradle installed, the common code will be built as part of the XCode build, without any special effort from your iOS devs.