You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is your feature request related to a problem? Please describe.
Adding implements InterfaceName to a type is not a breaking change (according to GraphQL Inspector, and I think community consensus) but it does mean that client behavior could change. I usually recommend that clients program defensively with a default: branch it their switch statements, like this:
The option would be disabled by default so that users could opt into this change.
Describe alternatives you've considered
You can always add // @ts-ignore in the default: clause, or cast it to any (thought this might trigger other linters):
console.log(`Unknown pet type ${(petasany).__typename}`);
Additional context
Ideally we could enforce adding the default: class with the switch-exhaustiveness-check eslint rule, but it only works on union types. I played around with something like
encapsulates the as any to be something you only have to write once
keeps the runtime behavior that a new implementation gets the console.log (or whatever you want it to be)
at build time, if a new implementation is added, then next time you run codegen it will fail to build (because pet is not actually never), which I think is what you want? (If it’s not what you want then just declare x: any instead and drop the as any)
Is your feature request related to a problem? Please describe.
Adding
implements InterfaceName
to a type is not a breaking change (according to GraphQL Inspector, and I think community consensus) but it does mean that client behavior could change. I usually recommend that clients program defensively with adefault:
branch it theirswitch
statements, like this:So that when
type Fish implements Pet
is added to the schema, the UI has some way of handling it.However, the
typescript-operations
plugin generates types like this:Which results in a TypeScript error:
Describe the solution you'd like
I'd like an option to the
typescript-operations
plugin that adds an additional type to the union type like this:The option would be disabled by default so that users could opt into this change.
Describe alternatives you've considered
You can always add
// @ts-ignore
in thedefault:
clause, or cast it toany
(thought this might trigger other linters):Additional context
Ideally we could enforce adding the
default:
class with theswitch-exhaustiveness-check
eslint rule, but it only works on union types. I played around with something likewhich did cause the exhaustiveness check to occur, but it feels hacky. But I bet someone with more TypeScript knowledge knows how to do this!
The text was updated successfully, but these errors were encountered: