Skip to content

Generate a Kotlin enum without the UNKNOWN__ case #6243

Closed as not planned
@joshuakcockrell

Description

@joshuakcockrell

Use case

Currently, when statements need to match .UNKNOWN__ every time they're used in a codebase.

when(color) {
  BLUEBERRY -> TODO()
  CANDY -> TODO()
  __UNKNOWN -> TODO()
} 

This means I need to think through the UNKNOWN fallback several times.

If the Apollo codegen provided an enum that didn't contain this case, I could instead write

when(color.unwrap()) {
  BLUEBERRY -> TODO()
  CANDY -> TODO()
} 

Yes, nothing's currently stopping me from writing an unwrap() extension, but I still need to sprinkle __UNKNOWN throughout my codebase to get the when statements to compile.

This is how Apollo iOS works, btw. GraphQLEnum.unknown is instead a wrapper enum around the core enum. On first glance, you would think Kotlin's approach is nicer because you don't need to match .case(...), but every single when statement needs a default case to handle the .UNKNOWN__, whereas iOS I can just create an unwrapper at the top level of my project to handle .unknown once.
Screenshot 2024-11-06 at 2 51 19 PM

Describe the solution you'd like

Screenshot_2024-11-06_at_2 29 15_PM

Apollo Kotlin already generates knownEntries List. If it just provided this exact thing in enum format I could write my own project level unwrap() and my individual when statements would never need to worry about .UNKNOWN__.

More context

Discord thread

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions