Open satvikpendem opened 6 months ago
đź‘‹ @satvikpendem Thank you for raising an issue. I will investigate the issue and get back to you as soon as possible. Please make sure you have provided enough context.
This library is created and maintained by me, @budde377. Please consider supporting my work and ensure our survival by donating here.
Thanks for raising this suggestion! I've been meaning to take a look at what faff we can remove and this seems like a good option.
I'm curious - if this is tackled, will it remove the need to also specify an orElse
equivalent?
If a given object can only be one of 2 object-types, it feels odd that we always have to provide an orElse
. To get around this we do this in many, many places :)
thing.when(
objectTypeOne: (one) => ...,
objectTypeTwo: (two) => ...,
orElse: () => throw Exception('Can not happen.'),
);
Which works fine but is a little silly.
Providing the orElse
even when all other cases have been “checked” is
useful if you want to build future-proof apps. It will allow you to add a
new type to your API without breaking existing apps.
Say that you add a type called ObjectType3
in your example, this would
throw an exception. You can then add a new case, but depending on your set
up, you might not be able to ensure that all your clients are updated.
On Thu, 6 Jun 2024 at 17:50, Greg Coladarci @.***> wrote:
I'm curious - if this is tackled, will it remove the need to also specify an orElse equivalent?
If a given object can only be one of 2 object-types, it feels odd that we always have to provide an orElse. To get around this we do this in many, many places :)
thing.when( objectTypeOne: (one) => ..., objectTypeTwo: (two) => ..., orElse: () => throw Exception('Can not happen.'), );
Which works fine but is a little silly.
— Reply to this email directly, view it on GitHub https://github.com/heftapp/graphql_codegen/issues/333#issuecomment-2152979124, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA2UFS5AOCH4P7DWNLNU7O3ZGCHNDAVCNFSM6AAAAABI5DQFA6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCNJSHE3TSMJSGQ . You are receiving this because you were mentioned.Message ID: @.***>
depending on your set up, you might not be able to ensure that all your clients are updated.
Thank you for this - a very good reason to have this, indeed...
Now that Dart 3 is here, you can likely replace the above two functions without loss of functionality, as
freezed
has also done here: