如何接受字典/对象作为石墨烯(GraphQL)突变的输入?

时间:2020-01-16 14:10:28

标签: python-3.x graphql graphene-python graphene-django

mutation{
createPayment(p_obj={"bob": 80, "job": 100}){
     <fields here>
     }
}

我可以找到的是接受对象列表作为输入,例如:

[ {username: "bob", "amount": 80}, {username: "job", "amount": 100} ]

1 个答案:

答案 0 :(得分:3)

您可以执行以下操作-

class PaymentInputType(graphene.InputObjectType):
      username = graphene.String()
      amount = graphene.Int()

并按如下所示在您的突变中使用InputType。

class CreatePayment(graphene.Mutation):
    class Arguments:
       input = PaymentInputType(required=True)

    ok = graphene.Boolean()

    @staticmethod
    def mutate(root, info, input):
        # save the changes here 
        return CreatePayment(ok=True)