python - 使用 InputObjectType 实例作为中继突变的输入
问题描述
根据 Graphene 文档,如果我们要在实现时从用户那里获取输入relay.clientIDMutation
,那么它需要在 Input 子类下,如下所示:
class Foo(relay.clientIDMuation):
class Input:
arg1 = graphene.String()
arg2 = graphene.Sring()
# the return parameters and mutate and get payload method after this
但是,我们也可以指定 InputObjectTypes。
class Bar(graphene.InputObjectType):
arg1 = graphene.String()
arg2 = graphene.String()
如果我们要使用普通的石墨烯突变对象,您可以在 Arguments 子类中使用指定输入。
class NewFoo(graphene.Mutation):
class Arguments:
input = Bar()
# return arguments and mutate method after this
当继承自 NewFoo 突变同时仍能够将 clientMutationID 作为输入参数传递时,如何Bar
将InputObjectType
其用于 Input 属性?relay.clientIDMutation
class NewFoo(relay.clientIDMutation):
class Attribute:
input = Foo()
# the return parameters and mutate and get payload method after this
注意:我已经尝试添加具有上述输入属性的 Arguments 子类,但是当类继承自relay.clientIDMuation
.
解决方案
您不需要class Attribute:
与relay.clientIDMutation
类一起使用。
尝试这个。在开始你的中继类之前声明这个类。
class Bar(graphene.InputObjectType):
arg1 = graphene.String()
arg2 = graphene.String()
在你的接力班里,
class NewFoo(relay.clientIDMutation):
class Input:
inputarray = Foo()
你的 Mutation 应该是这样的,
mutation{
NewFoo(input:{
inputarray:{
arg1:"Hello"
arg2:"world"
}
}
)
}
尽管您仍然无法将输入数组传递给该字段。
推荐阅读
- regex - 有没有办法有条件地替换字符串中的第一个'/'?
- reactjs - 报错找不到:POST http://localhost:8000/api/submit
- sql-server - 字段有前导零,在“UNION ALL”后被删除
- javascript - 动态重新加载页面时如何使用函数
- python - 根据 pandas 中 groupby 元素的大小创建新列
- python - 如何修复使用 MediaFileUpload 将文件上传到谷歌驱动器的程序?
- java - 将文件夹恢复到包中
- java - 如何从同名但数据不同的类中的类中获取数据?
- sql - 在 MS 访问查询中返回没有结果的值
- ios - 我应该如何使用 Swift 访问 iOS 上的数据库实例