Stylianos Gakis
12/11/2025, 10:41 AMunion SomeUnion = FirstCase|SecondCase|ThirdCase
And a type:
type TypeContent {
content: SomeUnion!
}
And in my query I got:
fragment "" on "" {
content {
...ContentFragment
}
}
fragment ContentFragment on SomeUnion {
...FirstFragment
...SecondFragment
...ThirdFragment
}
Then in my code at some point I am doing:
fun ContentFragment.toFoo(): Foo {
when(this) {
is FirstFragment -> ...
is SecondFragment -> ...
is ThirdFragment -> ...
else ->
}
}
When a new type is added to the original union, I need to add a new fragment etc. but then the code I got still look like it would work just fine without giving me any warnings, specifically because of the else -> in that last piece of code which covers the fact that I am not covering the new union case.
Is there any way at all for me to be able to prevent this? For example have the codegen to somehow generate ContentFragment as a sealed interface with an Unknown case for all unknown cases?
If it is not possible with the way I am doing it. Is there any other approach I can take so that I can get exhaustiveness when using unions like that?mbonnin
12/11/2025, 10:43 AMresponseBased codegen?Stylianos Gakis
12/11/2025, 10:44 AMMODELS_RESPONSE_BASED is what we are usingmbonnin
12/11/2025, 10:44 AMmbonnin
12/11/2025, 10:45 AMStylianos Gakis
12/11/2025, 10:48 AMStylianos Gakis
12/11/2025, 10:50 AM