我使用 graphene-django 来获得 GrapQL API。我在我的schema.py中创建了一个突变:
class UpdateApplication(graphene.Mutation):
class Input:
id = graphene.String()
name = graphene.String()
application = graphene.Field(ApplicationNode)
@classmethod
def mutate(cls, instance, args, info):
name = args.get('name')
rid = from_global_id(args.get('id'))[1]
update_application = Application.objects.filter(id=rid).update(name=name)
return UpdateApplication(application=update_application)
class Mutation(ObjectType):
update_application = UpdateApplication.Field()
schema = graphene.Schema(mutation=Mutation)
当我运行此请求时,出现错误。
mutation update {
updateApplication(id: "QXBwbGljYXRpb25Ob2RlOjE=", name: "foo") {
application {
name
}
}
}
错误:
mutate() takes exactly 4 arguments (5 given)
我在 mutate() 中放了 4 个参数,而不是 5...这是一个错误吗?