Ami*_*mir 5 graphql flask-graphql
I’m trying to created a list of objects using graphql mutation, but have been unsuccessful. I've identified the error, please see code snippets and comment on where the error is propagating.
Note: I'm using Graphene on Flask with Python 2.7
Here’s an example payload:
mutation UserMutation {
createUser(
phones: [
{
“number”: “609-777-7777”,
“label”: “home"
},
{
“number”: “609-777-7778”,
“label”: “mobile"
}
]
)
}
Run Code Online (Sandbox Code Playgroud)
On the schema, I have the following:
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!
Run Code Online (Sandbox Code Playgroud)
要将 dict 作为输入,您需要使用InputObjectType. (InputObjectTypes 就像 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()
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2005 次 |
| 最近记录: |