在 Amplify 中删除时出错 "Conflict resolver rejects mutation."

Error "Conflict resolver rejects mutation." when Delete in Amplify

我有一个简单的全栈放大应用程序。

这是我的模型:

type Note @model @auth(rules: [{allow: public}]) {
  id: ID!
  name: String!
  description: String
  image: String
  NoteType: NoteType @connection
}

type NoteType @model @auth(rules: [{allow: public}]) {
  id: ID!
  name: String!
}

我正在尝试删除具有以下负载的笔记:

{
    "query": "mutation DeleteNote($input: DeleteNoteInput!, $condition: ModelNoteConditionInput) {↵  deleteNote(input: $input, condition: $condition) {↵    id↵    name↵    description↵    image↵    createdAt↵    updatedAt↵    NoteType {↵      id↵      name↵      createdAt↵      updatedAt↵    }↵  }↵}↵",
    "variables": {"input": {"id": "0c5e3ced-ffa3-4de8-9010-40b67d5bab68"}}
}

我在回复中看到的内容如下json:

{
    "data": {
        "deleteNote": null
    },
    "errors": [
        {
            "path": [
                "deleteNote"
            ],
            "data": {
                "id": "0c5e3ced-ffa3-4de8-9010-40b67d5bab68",
                "name": "bb",
                "description": "bb",
                "image": "icon.png",
                "createdAt": "2020-12-21T12:00:26.743Z",
                "updatedAt": "2020-12-21T12:00:26.743Z"
            },
            "errorType": "ConflictUnhandled",
            "errorInfo": null,
            "locations": [
                {
                    "line": 1,
                    "column": 88,
                    "sourceName": null
                }
            ],
            "message": "Conflict resolver rejects mutation."
        }
    ]
}

代码一直有效,直到我尝试添加 NoteType!这里的外键有冲突吗?

使用 ConflictResolution 时,您还需要包含 _version 字段。

{
    "query": "mutation DeleteNote($input: DeleteNoteInput!, $condition: ModelNoteConditionInput) {↵  deleteNote(input: $input, condition: $condition) {↵    id↵    name↵    description↵    image↵    createdAt↵    updatedAt↵    NoteType {↵      id↵      name↵      createdAt↵      updatedAt↵    }↵  }↵}↵",
    "variables": {"input": {"id": "0c5e3ced-ffa3-4de8-9010-40b67d5bab68", "_version": "_version value of your note object"}}
}

我还注意到,在删除使用冲突解决方案的元素后,它们并没有立即从数据库中删除。相反,添加了两个标志:_deleted 设置为 true,_ttl 设置为对象在 30 天后过期。