簡體   English   中英

AWS Amplify CLI 生成的 GraphQL 突變中的 $condition 輸入參數是什么?

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM