python-3.x - 如何接受字典/对象作为石墨烯(GraphQL)突变的输入?
问题描述
mutation{
createPayment(p_obj={"bob": 80, "job": 100}){
<fields here>
}
}
我能找到的是接受一个对象列表作为输入,例如:
[ {username: "bob", "amount": 80}, {username: "job", "amount": 100} ]
解决方案
你可以做这样的事情 -
class PaymentInputType(graphene.InputObjectType):
username = graphene.String()
amount = graphene.Int()
并在您的突变中使用 InputType,如下所示。
class CreatePayment(graphene.Mutation):
class Arguments:
input = PaymentInputType(required=True)
ok = graphene.Boolean()
@staticmethod
def mutate(root, info, input):
# save the changes here
return CreatePayment(ok=True)
推荐阅读
- oracle - Using Oracle Data Integrator 12c with Snowflake
- python - Python - Extracting weight from a column (containing a string) in a Pandas DataFrame using regex and adding it to a new column
- python - 使用 Spotipy API 循环遍历数据框和搜索轨道?
- javascript - 如何比较两个对象数组并纠正相同的键值?
- amazon-web-services - 是否可以在网关 VPC 端点前面放置网络负载均衡器?
- java - 无法在 Ubuntu 中使用 Java Mail 发送邮件
- html - 如何为手机添加响应式按钮?按钮需要堆叠成一列。有困难
- python - Scipy Stats Wilcoxon X 和 Y 必须是一维误差
- php - Laravel 中的 withTest1($a) 和 compact($a) 有什么区别?
- ruby-on-rails - 使用带有嵌套原始 JSON 参数的强参数