我正在尝试使用graphql mutation
创建对象列表,但一直未成功。我已经确定了错误,请参阅代码段并评论错误传播的位置。
注意:我在Flask上使用Graphene使用Python 2.7
这是一个示例有效载荷:
mutation UserMutation {
createUser(
phones: [
{
“number”: “609-777-7777”,
“label”: “home"
},
{
“number”: “609-777-7778”,
“label”: “mobile"
}
]
)
}
在架构上,我有以下内容:
class CreateUser(graphene.Mutation):
ok = graphene.Boolean()
...
phones = graphene.List(graphene.String()) # this is a list of string but what I need is a list of dicts!
答案 0 :(得分:3)
要将字典作为输入,您需要使用InputObjectType
。 (InputObjectType
s类似于ObjectTypes,但仅用于输入数据。)
此示例适用于石墨烯1.0
。
class PhoneInput(graphene.InputObjectType):
number = graphene.String()
label = graphene.String()
class CreateUser(graphene.Mutation):
class Input:
phones = graphene.List(PhoneInput)
ok = graphene.Boolean()
class Mutation(graphene.ObjectType):
create_user = CreateUser.Field()