Python 如何使用graphql发送对象数组
我有如下图:Python 如何使用graphql发送对象数组,python,reactjs,graphql,graphene-python,Python,Reactjs,Graphql,Graphene Python,我有如下图: const RESET_PASSWORD = gql` mutation ResetPassword($input: [ResetPasswordInput]!) { resetPassword(input: $input) { ok } } `; resetPassword() { const {mutation, onClose, users} = this.props; mutation.mutate({
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"
}
]
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}]}]}
需要执行变异的函数如下:
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"
}
]
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}]}]}
我想向后端发送一个用户对象数组。数组如下所示:
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"
}
]
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}]}]}
在后端,我使用Python和Graphenne。代码如下:
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"
}
]
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}]}]}
但我不断得到如下错误:
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"
}
]
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}]}]}
我做错了什么?我在graphene方面没有什么大手笔,但我认为这行代码可能有帮助``类重置密码(graphene.Mutation):类参数:输入=graphene.List(ResetPasswordInput)或类重置密码(graphene.Mutation):类输入:输入=graphene.List(ResetPasswordInput)```