gpt4 book ai didi

c# - 是否可以在 GraphQL 中发送具有多个值的 Enum

转载 作者:行者123 更新时间:2023-12-04 04:13:16 25 4
gpt4 key购买 nike

在 C# 中,可以创建一个带有标志属性的枚举。( https://docs.microsoft.com/en-us/dotnet/api/system.flagsattribute?view=netstandard-2.1 )
这意味着一个 Enum 可以是这样的:

[Flags]
enum EnumWithFlags
{
None = 0,
FlagOne = 1,
FlagTwo = 2,
FlagThree = 4
}

EnumWithFlags 的值为 5,这意味着它将同时具有 FlagThree 和 FlagOne。

这也可以使用 Enum 输入类型吗?有没有这样的例子?

最佳答案

来自 Schemas and Types :

Enumerations types are a special kind of scalar that is restricted to a particularset of allowed values.


基本上,如果您希望将其作为枚举,则必须将每个标志组合定义为一个单独的值。
更好的解决方案可能是使用向量,您可以在其中设置列表中的多个枚举值:
    type Foo {
flags: [EnumWithFlags]
}

enum EnumWithFlags {
NONE
FLAG_ONE
FLAG_TWO
FLAG_TREE
}
更新了,也有人回答了 here

关于c# - 是否可以在 GraphQL 中发送具有多个值的 Enum,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61268907/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com