HotChocolate 在所有大写蜗牛情况下序列化枚举值,这导致枚举值FooBar
被 Hot Chocolate 推断FOO_BAR
,但value.ToString()
给出Enum.GetName(value)
了 FooBar,而 Hot Chocolate 似乎忽略了[EnumMember(Value = "FooBar")]
.
如何将序列化更改为我想要的任何方式?
HotChocolate 在所有大写蜗牛情况下序列化枚举值,这导致枚举值FooBar
被 Hot Chocolate 推断FOO_BAR
,但value.ToString()
给出Enum.GetName(value)
了 FooBar,而 Hot Chocolate 似乎忽略了[EnumMember(Value = "FooBar")]
.
如何将序列化更改为我想要的任何方式?
HotChocolate server v11 遵循规范建议,默认枚举值被序列化为 UPPER_SNAIL_CASE。
你可以这样改变:
builder
.AddConvention<INamingConventions>(new YourNamingConvention())
public class YourNamingConvention
: DefaultNamingConventions
{
public override NameString GetEnumValueName(object value)
{
if (value == null)
{
throw new ArgumentNullException(nameof(value));
}
return value.ToString().ToUpperInvariant(); // change this to whatever you like
}
}