3

HotChocolate 在所有大写蜗牛情况下序列化枚举值,这导致枚举值FooBar被 Hot Chocolate 推断FOO_BAR,但value.ToString()给出Enum.GetName(value)了 FooBar,而 Hot Chocolate 似乎忽略了[EnumMember(Value = "FooBar")].

如何将序列化更改为我想要的任何方式?

4

1 回答 1

5

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
        }
    }
于 2021-03-25T20:45:51.283 回答