Hello! I'm currently experimenting with migrating ...
# apollo-kotlin
m
Hello! I'm currently experimenting with migrating an existing project to Kotlin multiplatform and I have a question. Some details about the project: • 1 android app that uses apollo-android (v2.5.14), in its own repo. ◦ It's not in the plan to migrate to a newer version of apollo in the short term, as we rely heavily on LiveData and it would require quite some time to switch to coroutines. • 1 iOS app that uses apollo-ios (v1.2.2), in its own repo. What I would like to do: • Switch to a monorepo that would have ios, android and shared (KMP) • Share networking / repository code between Android and iOS (for new features, not in the plan to refactor existing code for now) • Use the latest version of apollo-kotlin in the shared part. My main question: is it possible to use apollo-kotlin 4.x in the shared code part, while also using apollo-android (v2.x) in the android code (can both live together)? Bonus question: is it possible to have the graphql queries (.graphql files) stored in the shared folder, while having the shared module generating code using apollo-kotlin 4.x and the android module generating code from those same graphql files using apollo-android 2.x (and storing them in the android module)?
b
Hi! Having both 2.x and 4.x in the same project should be possible. The Gradle plugins have separate ids, and the dependencies reside in different packages. For 2nd question I think it's possible but I'm not sure I understand - do you intend to have the generated code twice? One from 2.x, one from 4.x?
m
Thanks for the quick answer 🙂. For 2nd question, I hope this image can provide more info. In the end, the goal of doing this is to have only one folder for all .graphql files (stored in commonMain/graphql), instead of needing to put some .graphql files in commonMain/graphql and some in android/src/main/graphql.
b
yes this is possible, you can configure where to find the graphql files in your android module with 2.x (with
sourceFolder
) and by putting them there they'll also be picked up by your shared module with 4.x. But just a warning that this means the code will be generated twice then.
m
It's not working for me. This is my code in the android/build.gradle file:
Copy code
apollo {
    schemaFile.set(rootProject.file("shared/src/commonMain/graphql/schema.json"))
    rootPackageName.set("com.myapp.android.graphql")

    generateKotlinModels.set(true)

    graphqlSourceDirectorySet.srcDirs("shared/src/commonMain/graphql/mobile-graphql")
    graphqlSourceDirectorySet.exclude("**/*.md")
}
When I execute android:generateApolloSources I get nothing in android/build/src/graphql
b
not exactly sure about relative vs absolute paths - could you try
Copy code
graphqlSourceDirectorySet.srcDirs("${rootProject.projectDir}/shared/src/commonMain/graphql/mobile-graphql")
?
m
MY MAN!
😅 1
🎉 1
It works 🙂. Thanks
b
sure thing!