Medium Android App — Migrating from Apollo Kotlin 3 to 4: Lessons Learned
Article Summary
Pierrick CAEN from Medium thought upgrading Apollo Kotlin would be straightforward. Instead, it exposed hidden cache issues that had been silently failing for months.
The Medium Android team migrated from Apollo Kotlin 3 to 4, discovering that the new version's stricter exception handling revealed fundamental problems with their GraphQL cache implementation. What started as a routine upgrade became a complete overhaul of their caching strategy.
Key Takeaways
- Apollo 4 exposes CacheMissExceptions that version 3 silently ignored with CacheFirst policy
- Switched from programmatic to declarative cache IDs for easier type matching
- Created custom extension functions to handle cache reads/writes with proper error logging
- Different fetch policies require different exception filtering (CacheFirst vs NetworkFirst)
- Added typename to all operations and Currency scalar adapters for better performance
Upgrading Apollo Kotlin 4 forces you to fix cache configuration issues that were previously hidden, leading to more robust GraphQL implementations.
About This Article
Apollo Kotlin 4 started throwing CacheMissExceptions that version 3 had quietly ignored. This broke the Medium Android app's watch() functionality wherever FetchPolicy.CacheFirst was used, causing failures across the UI.
Pierrick CAEN added declarative cache IDs using @typePolicy and @fieldPolicy annotations. He set addTypename to 'always' in the Gradle build file and wrote safeWatch() extension functions that filter out expected exceptions based on the fetch policy type.
Cache hit rates improved noticeably once cache IDs matched types and fields correctly. The silent cache misses that had been a problem in their GraphQL implementation went away, leaving them with a more reliable caching strategy.