graphql-platform
graphql-platform copied to clipboard
Extending enum values set results in breaking changes in StrawberryShake client
Is there an existing issue for this?
- [X] I have searched the existing issues
Product
Strawberry Shake
Describe the bug
If I extend a given enum with a new value, then the client generated by StrawberryShake treats that value as incorrect and throws an exception. This prevents the server from extending the contract without breaking all clients. Adding a new version of the contract (v2, v3, etc) just because a single enum has been extended imposes huge maintenance costs.
Adding a new enum value should not be treated as breaking changes. There should be a configuration switch to override this behaviour. Ideally, the generated enum should have an extra value like "UKNOWN", and the de-serialised should map all values outside the known set to this special element. This will allow the developer to handle this situation directly in their code.
I'm not sure if this issue should be threatened as a bug, but I use StrawberryShake to generate my clients and now I'm in a very uncomfortable position ;)
Steps to reproduce
- Create a graphql server that returns an enum value
- Generate client using StrawberryShake
- Extend enum values on the server with a new option
- Now the client throws an exception if the returned set contains an entity with the new enum value
The expected generated code should look something like that:
public enum SampleEnumType
{
Unknown, // Extra option to represents all values that client doesn't know about
One,
Two
}
public ContractExecutionType Parse(global::System.String serializedValue)
{
return serializedValue switch
{
"ONE" => SampleEnumType.One,
"TWO" => SampleEnumType.Two,
_ => SampleEnumType.Unknown // Map all new values to `Unknown `
}
}
Relevant log output
No response
Additional Context?
No response
Version
13.8.1.0
I am willing to help with the implementation but can anyone comment on the solution? This is very serious problem for me. cc: @michaelstaib
This is a major issue for us as well! Are there any good work arounds for now?