I have a .NET Core GraphQL backend service consumed in a Blazor web assembly app with a GetData GraphQL query with an enum like this:
public enum SomeEnumTypes : byte
{
None,
First,
SecondItem
}
When the data is returned from the backend in that query, SecondItem from enum is returned as SECOND_ITEM to client but it results in an error:
Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100]
Unhandled exception rendering component: Error converting value "SECOND_ITEM" to type 'SomeEnumTypes'. Path 'data.GetData[0].someEnumType', line 1, position 1375.Newtonsoft.Json.JsonSerializationException: Error converting value "SECOND_ITEM" to type 'SomeEnumTypes'. Path 'data.GetData[0].someEnumType', line 1, position 1375.
System.ArgumentException: Requested value 'SECOND_ITEM' was not found.
at Newtonsoft.Json.Utilities.EnumUtils.ParseEnum(Type enumType, NamingStrategy namingStrategy, String value, Boolean disallowNumber)
at Newtonsoft.Json.Converters.StringEnumConverter.ReadJson(JsonReader reader, Type objectType, Object existingValue, JsonSerializer serializer)
SomeEnumTypes enum is in a third party nuget library so I can't make any changes to the enum directly.
I tried multiple ways including writing custom converters for the Newtonsoft serializer with regex to handle underscores and even creating a dictionary for that enum to convert in the converter but no use.
_graphqlClient = new GraphQLHttpClient(_configuration.GetValue<string>("SomeKey"), new NewtonsoftJsonSerializer(options =>
{
options.Converters.Add(new SomeConverter())
}));
Is there something I am missing? Help would be appreciated.