apollographql / apollo-kotlin

:rocket:  A strongly-typed, caching GraphQL client for the JVM, Android, and Kotlin multiplatform.
https://www.apollographql.com/docs/kotlin
MIT License
3.77k stars 656 forks source link

Compiler plugin `onSchema()` is not ergonomic in multi-module setups #6251

Closed rohandhruva closed 1 week ago

rohandhruva commented 2 weeks ago

Use case

We are trying to use the compiler plugin onSchema() method to generate some custom code using kotlin-poet. Previously, we did this using a custom gradle task. We have a multi-module setup.

The onSchema method is a much better fit for our use case: we no longer need to "hook into" apollo internals to convert the file to a schema. However, the downside is that the onSchema method is called multiple times: once for each module.

This means that our codegen ends up running multiple times, creating duplicate files. Ideally, we would want to run this once only, for the schema module, and not for the feature modules. This is currently not very easy to do. Our workaround was to pass an argument to the plugin, e.g. isSchemaModule, and use that to determine whether to run the codegen or not.

Describe the solution you'd like

Perhaps the onSchema method of the SchemaListener can provide some more information about the module being operated on? Is there a clear way to identify schema vs feature modules?