Question about exhaustively covering all Union cas...
# apollo-kotlin
s
Question about exhaustively covering all Union cases Given a Union like:
Copy code
union SomeUnion = FirstCase|SecondCase|ThirdCase
And a type:
Copy code
type TypeContent {
  content: SomeUnion!
}
And in my query I got:
Copy code
fragment "" on "" {
 content {
  ...ContentFragment
 }
}

fragment ContentFragment on SomeUnion {
  ...FirstFragment
  ...SecondFragment
  ...ThirdFragment
}
Then in my code at some point I am doing:
Copy code
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?
m
Are you using
responseBased
codegen?
s
Yeah,
MODELS_RESPONSE_BASED
is what we are using
m
I see. I think we can probably make that base interface sealed indeed
🦜 2
I'm AFK right now but sounds like something we should have done. I don't think anyone will implement custom classes on top of the codegen interfaces
s
Since you are AFK I created this https://github.com/apollographql/apollo-kotlin/issues/6809 so that it's not lost in some slack conversation, but it's part of GitHub instead 🤗
thank you color 1
Please help correct me if something I am writing in the issue is odd. I am not sure if I am using all the terms correctly in my attempt to describe what I want to describe 😄