![](/img/trans.png)
[英]AWS Amplify GraphQL CreateOrUpdate / Upsert mutation
[英]What is the $condition input parameter for in a GraphQL mutation generated by AWS Amplify CLI?
我从这个 model 在 AWS AppSync 上(使用 CLI)生成了一个简单的 GraphQL API:
type WalletProperty @model {
id: ID!
title: String!
}
这生成了一个 CreateWalletProperty、UpdateWalletProperty 和 DeleteWalletProperty 突变,都与此类似:
mutation CreateWalletProperty(
$input: CreateWalletPropertyInput!
$condition: ModelWalletPropertyConditionInput <<<<<<<<<<<< what is this for?
) {
createWalletProperty(input: $input, condition: $condition) {
id
title
createdAt
updatedAt
}
}
条件的模式是:
input ModelWalletPropertyConditionInput {
title: ModelStringInput
and: [ModelWalletPropertyConditionInput]
or: [ModelWalletPropertyConditionInput]
not: ModelWalletPropertyConditionInput
}
鉴于我总是必须提供强制性的 $input,$condition 参数有什么用?
在我上面的例子中,GraphQL 由 DynamoDB 表支持;
在幕后,GraphQL 操作转换为 PutItem、UpdateItem 和 DeleteItem DynamoDB 操作。
对于这些数据操作操作,DynamoDB API 允许您指定条件表达式来确定应修改哪些项目。 如果条件表达式的计算结果为真,则操作成功; 否则,操作失败。
您可以在 AWS 条件表达式 DynamoDB 开发指南上阅读有关每个条件的用例的更多信息
在GraphQL突变级别,只有记录满足条件,才会提前突变go。 否则不允许更改并返回 ConditionalCheckFailedException:
"errors": [
{
"path": [
"deleteWalletProperty"
],
"data": null,
"errorType": "DynamoDB:ConditionalCheckFailedException",
"errorInfo": null,
"locations": [
{
"line": 12,
"column": 3,
"sourceName": null
}
],
"message": "The conditional request failed (Service: DynamoDb, Status Code: 400, Request ID: E3PR9OM6M5J1QBHKNT8E4SM1DJVV4KQNSO5AEMVJF66Q9ASUAAJG, Extended Request ID: null)"
}
]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.