hey - I'm pretty new to using the Apollo Gradle Pl...
# apollo-kotlin
p
hey - I'm pretty new to using the Apollo Gradle Plugin and GraphQL. I noticed that the
generateApolloSources
task will generate some data classes that are exactly the same, is there a way to configure the plugin so that only one of each of these classes is generated and they are re-used in the respective queries?
👋 1
m
Howdy 👋 Welcome here! You'll want to use fragments. Because in GraphQL different queries might query different set of fields, we can't generate the same models by default.
If all your queries reuse the same fields, using fragments is a nice way to factor some of that logic as the generated models will be shared between queries
p
awesome I'll give that a go thanks Martin
a
We do that heavily and it works great! Just ensure you organize your modules if you plan to have queries in different modules to share a common base graphql module
s
Side-tracking here, but a question to Andrew regarding having queries in separate modules. The way we’ve set it up, is that we have one “:apollo” module, which contains • all the queries/mutations • some convenience functions to transform to arrow’s Either and so on, • All of our com.apollographql.apollo3.api.Adapter that we have and we have every other module depend on this directly. This has been working rather well for us, and we haven’t had the need to split it down further. Is the thing you’re solving basically inside a feature module not being able to access other feature’s queries/mutations by accident? Just so you won’t make the mistake of calling the wrong gql call? It has never occured to me to split those up so far, so I am wondering if there’s anything else that I am missing out on 😄
a
We decided to split it out by domain type rather than just a single module in order to prevent bottlenecks in our builds for parallelization. We have an old graphql module called “models” which over 75 modules depend on to build first lol so just optimizations.
Also then teams can own specific modules for those graphql queries if need be. Most cases I envision were using the mostly the same set of fragment types but most queries will only get used in one feature.
s
Yeap sounds fair to me, especially if you got different teams work on different parts! Thanks for the reply 😊
a
anytime!