graphql-client
graphql-client copied to clipboard
Add PolymorphicTypenameConverter class to handle __typename deserialization
Attached a helper class I found very useful to handle fragments and __typename deserialization:
Usage:
[JsonConverter(typeof(DiscriminateEvent))]
public Event Event { get; set; }
class DiscriminateEvent : PolymorphicTypenameConverter<Event>
{
protected override Type Descriminator(string typename) =>
typename switch
{
"EventA" => typeof(EventA),
"EventB" => typeof(EventB),
_ => typeof(Event)
};
}
I think there should be also a example within the readme cause its not obvious how to use it.
But for now I want to know what you think first and if its a nice addition.
@lanwin Would you like to continue working on it?
@lanwin Would you like to continue working on it?
Yes but I am not sure yet whats expected from here.
@rose-a ?
It would be great to see this or something like this supported! It is a great idea, though it looks like it has lost some momentum over the past year...
Works like a charm when using unions for error handling. Would like to see it merged into the library. Cheers!