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.7k stars 650 forks source link

Handle Compose stability #5732

Open BoD opened 3 months ago

BoD commented 3 months ago

The models generated by Apollo Kotlin are immutable, and therefore should participate in skipping recomposition. However list fields are generated with List<T> which is considered unstable by Compose.

More information about Compose stability here.

We could mark the generated models with @Immutable but that implies with a dependency to androidx.compose.runtime:runtime, so we would need to make this configurable

In the meantime users can already mark the generated models as stable manually with the Compose compiler configuration file

StylianosGakis commented 2 months ago

I wonder if you should just rely on strong-skipping mode instead https://medium.com/androiddevelopers/jetpack-compose-strong-skipping-mode-explained-cbdb2aa4b900 and not have to worry about doing such optimizations on the apollo-kotlin end. My understanding is that strong skipping will be enabled by default in the future and as long as the generated models generate proper .equals functions, which they do, then it might just be fine to not do anything here

BoD commented 2 months ago

Thanks a lot for sharing, interesting stuff! From what I gather, it sounds like with this change, stability won't be as important as it was.

It still doesn't hurt and is pretty easy to mark all generated classes as stable with the configuration file. Maybe this ticket is just to document how to do this somewhere in our docs.

StylianosGakis commented 2 months ago

Yeah that is fair, as long as you do not mind having the annotation in the sources, and you anyway guarantee that those classes are immutable, then adding the annotation is also safe enough that it shouldn't matter.

But I agree with keeping the ticket open. Strong skipping mode isn't on by default yet anyway.