gpt4 book ai didi

python - Graphite 烯的错误。突变?

转载 作者:太空宇宙 更新时间:2023-11-04 00:44:22 28 4
gpt4 key购买 nike

我使用 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 个...这是一个错误吗?

最佳答案

从 graphene 1.0 开始,上下文现在默认传递给 mutation 和 resolve 函数,而在以前的版本中它需要 @with_context : https://github.com/graphql-python/graphene/blob/master/UPGRADE-v1.0.md

所以你的 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)

关于python - Graphite 烯的错误。突变?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40427247/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com