Is there any way to disable the `__UNKNOWN` elemen...
# apollo-kotlin
r
Is there any way to disable the
__UNKNOWN
elements for enums? They are annoying because they basically break exhaustive whens. I'd rather have the compiler tell me a new enum was added and it needs to be handled rather than dealing with
__UNKNOWN
explicitly everywhere.
And in this particular case, backward compatibility is not a concern because its a server-side app.
d
Doesnt matter whether it is server side app or not -> there is always a chance that enum definitions can get out of sync between your client and server (ie deploy new version of server with added/removed enum value)
By automatically handling the unknown value we wont blow up our apps in those situations
*you certainly can throw exceptions on unknows but that is your explicit choice vs uncaught exception trying to serialize some unknown value
r
*you certainly can throw exceptions on unknows but that is your explicit choice vs uncaught exception trying to serialize some unknown value
Right. I'm asking about how to make that choice once at code gen time rather than at every place I use an enum in my code -- I'm fine with a runtime exception on an out of sync enum value.
Doesnt matter whether it is server side app or not
Of course it does. I control the lifecycle of a server-side app (as opposed to a mobile app, say). Therefore the risk of an unknown enum, while possible, is both a) known, and b) controllable.
d
this is just my assumption -> but since you are using codegen for client I assume your server-side app is calling ANOTHER GraphQL service --- is the above correct?
r
Right, and I deploy both server-side apps, "client" and server, together and have retry logic for transient failures for slightly out of sync deploys.
d
IMHO it is just a good practice to handle the unknown failures but in this situation the issue might be very limited. Unsure if you can disable the behavior - @mbonnin will know
m
There's no such option indeed because of everything @Dariusz Kuc said. Feel free to open an issue for the feature request
r
Thx @mbonnin -- not worth it 🙂 I'll continue to add the appropriate checks for
__UNKNOWN
.
👍 1