Medium's Android team migrated from Apollo Kotlin 3 to 4, encountering significant cache-related challenges. The migration exposed issues with their programmatic cache ID implementation, leading to frequent CacheMissException errors. They resolved this by switching to declarative cache IDs, adding __typename to all operations, and implementing custom exception handling for different fetch policies. The team also created extension functions for cache updates and added custom type adapters for scalar values, ultimately improving cache hit rates and overall GraphQL implementation robustness.
Table of contents
Understanding Our Apollo Cache ImplementationStarting the MigrationKey Changes in Apollo Kotlin 4The Challenge: Cache Miss ExceptionsGet Pierrick CAEN’s stories in your inboxFixing the Cache ImplementationSolution: Declarative Cache IDs & __typename on all OperationsCache Update Extension FunctionsTesting and Handling Cache ExceptionsCompleting the MigrationAdditional Improvements: Custom Type AdaptersFuture ImprovementsHTTP BatchingPersisted QueriesConclusionSort: