[英]Bug with graphene.Mutation?
I use graphene-django for have a GrapQL API. 我使用graphene-django提供了GrapQL API。 I have created a mutation in my schema.py : 我在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)
When I run this resquest, I have an error. 运行此请求时,出现错误。
mutation update {
updateApplication(id: "QXBwbGljYXRpb25Ob2RlOjE=", name: "foo") {
application {
name
}
}
}
The error: 错误:
mutate() takes exactly 4 arguments (5 given)
I put 4 arguments in mutate() not 5... Is it a bug? 我在mutate()中输入了4个参数,而不是5个...这是一个错误吗?
As of graphene 1.0, the context is now passed to mutation and resolve functions by default whereas it required @with_context in previous versions: https://github.com/graphql-python/graphene/blob/master/UPGRADE-v1.0.md 从graphene 1.0开始,上下文默认情况下会传递给mutation和resolve函数,而在以前的版本中则需要@with_context: https : //github.com/graphql-python/graphene/blob/master/UPGRADE-v1.0。 MD
So your mutate functions should look like: 因此,您的mutate函数应如下所示:
def mutate(self, args, context, 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)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.