Luk*_*ssa 6 graphql aws-appsync graphql-mutation graphql-codegen
我已从此模型在 AWS AppSync 上(使用 CLI)生成了一个简单的 GraphQL API:
type WalletProperty @model {
id: ID!
title: String!
}
Run Code Online (Sandbox Code Playgroud)
这生成了 CreateWalletProperty、UpdateWalletProperty 和 DeleteWalletProperty 突变,所有这些都与此类似:
mutation CreateWalletProperty(
$input: CreateWalletPropertyInput!
$condition: ModelWalletPropertyConditionInput <<<<<<<<<<<< what is this for?
) {
createWalletProperty(input: $input, condition: $condition) {
id
title
createdAt
updatedAt
}
}
Run Code Online (Sandbox Code Playgroud)
条件的模式是:
input ModelWalletPropertyConditionInput {
title: ModelStringInput
and: [ModelWalletPropertyConditionInput]
or: [ModelWalletPropertyConditionInput]
not: ModelWalletPropertyConditionInput
}
Run Code Online (Sandbox Code Playgroud)
鉴于我总是必须提供强制性的 $input,$condition 参数有什么用?
在我上面的例子中,GraphQL 由 DynamoDB 表支持;
在幕后,GraphQL 操作会转换为 PutItem、UpdateItem 和 DeleteItem DynamoDB 操作。
对于这些数据操作操作,DynamoDB API 允许您指定条件表达式来确定应修改哪些项目。如果条件表达式的值为 true,则操作成功;否则操作失败。
您可以在 AWS条件表达式 DynamoDB 开发指南上了解有关每个条件的用例的更多信息
在 GraphQL 突变级别,只有记录满足条件,突变才会继续。否则不允许突变并返回 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)"
}
]
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3858 次 |
| 最近记录: |