如何发送带有graphql突变的对象数组

时间:2019-05-20 10:55:14

标签: python reactjs graphql graphene-python

我的grapgql突变如下:

const RESET_PASSWORD = gql`
mutation ResetPassword($input: [ResetPasswordInput]!) {
    resetPassword(input: $input) {
        ok
    }
  }
`;

需要执行突变的功能如下:

resetPassword() {
        const {mutation, onClose, users} = this.props;
        mutation.mutate({
            variables: {
                input: users
            }
        }, (result) => {
            if (result.success) {
                onClose()
            }
        })
    }

我想将用户对象数组发送到后端。数组如下:

users = [
    {
        company_id: "14",
        company_user_id: "10313",
        email: "some_email@ehotmail.com",
        state: "APPROVED",
        token: "5aaa0cd6caac022cf0829860abc42e955ab4c65b",
        user_id: "21591"
    },
    {
        company_id: "14",
        company_user_id: "10314",
        email: "some_email1@ehotmail.com",
        state: "APPROVED",
        token: "5aaa0cd6caac022cf0829860abc42e955ab4c65c",
        user_id: "21592"
    }
]

在后端,我正在使用Python和Graphenne。代码如下:

class ResetPasswordInput(graphene.InputObjectType):
    user_id = graphene.Int(required=True)
    email = graphene.String(required=True)
    token = graphene.String(required=True)
    state = graphene.String()
    user_company_id = graphene.Int(required=True)
    company_id = graphene.Int(required=True)


class ResetPassword(graphene.Mutation):
    class Arguments:
        input = graphene.List(ResetPasswordInput, required=True)

    ok = graphene.Boolean()

    @staticmethod
    def mutate(self, info, input):
        pdb.set_trace()
        ok = True
        # Send email

        return ResetPassword(ok=ok)


class Mutation(graphene.ObjectType):
    reset_password = ResetPassword.Field()

但是我一直收到如下错误:

{"errors":[{"message":"Variable \"input\" of type \"[ResetPasswordInput]!\" used in position expecting type \"ResetPasswordInput!\".","locations":[{"line":1,"column":24},{"line":2,"column":24}]}]}

我在做什么错了?

0 个答案:

没有答案