graphql-platform icon indicating copy to clipboard operation
graphql-platform copied to clipboard

Extending enum values set results in breaking changes in StrawberryShake client

Open cezarypiatekGC opened this issue 1 year ago • 2 comments

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

  1. Create a graphql server that returns an enum value
  2. Generate client using StrawberryShake
  3. Extend enum values on the server with a new option
  4. 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

cezarypiatekGC avatar Jan 29 '24 08:01 cezarypiatekGC

I am willing to help with the implementation but can anyone comment on the solution? This is very serious problem for me. cc: @michaelstaib

cezarypiatekGC avatar Feb 12 '24 12:02 cezarypiatekGC

This is a major issue for us as well! Are there any good work arounds for now?

jaredromano avatar Apr 09 '24 15:04 jaredromano