【发布时间】:2019-10-09 02:39:56
【问题描述】:
我目前在突变枚举 Argument 上遇到困难。
下面是我的Mutation代码:
class CreatePerson(graphene.Mutation):
foo = graphene.String()
def mutate(self, info, **kwargs):
return CreatePerson(foo='foo')
class Arguments:
enum_arg = graphene.Argument(graphene.Enum.from_enum(EnumArg))
枚举类:
from enum import Enum
class EnumArg(Enum):
Baz = 0
Bar = 1
Spam = 2
Egg = 3
使用POSTMAN的命令:
{
"query": "mutation": {createPerson(enumArg=1) { foo }}
}
但我最终得到了这个错误消息:
"message": "Argument \"enumArg\" has invalid value 1.
Expected type \"EnumArg\", found 1.",
我还尝试在createPerson 突变上提供enumArg=\"Bar\",但错误仍然存在。
【问题讨论】:
-
command无效 python 你怎么称呼command? -
不,它非常有效。在这里检查并使用邮递员stackoverflow.com/a/55146271/6143656
-
@MarcoDaniel 看起来不错
-
不确定这是不是骗子。这里的问题是我们可以为每个枚举值分配一个任意值,但这个值仅由 GraphQL 服务本身在内部使用。在 GraphQL 文档中引用枚举值时,必须始终通过其名称来引用。
-
@Roel 这可能是一个好问题,不幸的是我无法回答,因为我没有使用
flask-sqlalchemy的经验。我建议打开一个新问题。
标签: python graphql graphene-python