Company
Date Published
Author
Martin Bonnin
Word count
2386
Language
English
Hacker News points
None

Summary

The story behind Apollo Kotlin 3 codegen is a complex and nuanced one, with multiple tradeoffs involved. The release of Apollo Kotlin 3 in December 2021 marked a significant milestone for the project, but it also presented several challenges. The initial goal was to generate type-safe models from GraphQL operations, but this proved to be more complicated than expected. After exploring different approaches, including mapping GraphQL types to Kotlin interfaces and generating classes based on operations, the team decided to implement a new codegen system that takes into account the complexities of fragments and nested fields. This response-based codegen offers several benefits, including the ability to stream JSON responses, store merged fields only once, and allow polymorphism. However, it also presents challenges, such as exponentially growing codegen and name clashes due to limitations on file names. Ultimately, the choice between operation-based and response-based codegen depends on the specific needs of each project, with operation-based being more compatible with 2.x and easier to grasp, but offering less type information and performance.