错误“冲突解决程序拒绝突变。” 当在放大中删除时

Mah*_*ari 8 reactjs graphql aws-amplify

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

\n

这是我的模型:

\n
type Note @model @auth(rules: [{allow: public}]) {\n  id: ID!\n  name: String!\n  description: String\n  image: String\n  NoteType: NoteType @connection\n}\n\ntype NoteType @model @auth(rules: [{allow: public}]) {\n  id: ID!\n  name: String!\n}\n
Run Code Online (Sandbox Code Playgroud)\n

我正在尝试删除具有以下有效负载的注释:

\n
type Note @model @auth(rules: [{allow: public}]) {\n  id: ID!\n  name: String!\n  description: String\n  image: String\n  NoteType: NoteType @connection\n}\n\ntype NoteType @model @auth(rules: [{allow: public}]) {\n  id: ID!\n  name: String!\n}\n
Run Code Online (Sandbox Code Playgroud)\n

我在响应中看到的是以下 json:

\n
{\n    "query": "mutation DeleteNote($input: DeleteNoteInput!, $condition: ModelNoteConditionInput) {\xe2\x86\xb5  deleteNote(input: $input, condition: $condition) {\xe2\x86\xb5    id\xe2\x86\xb5    name\xe2\x86\xb5    description\xe2\x86\xb5    image\xe2\x86\xb5    createdAt\xe2\x86\xb5    updatedAt\xe2\x86\xb5    NoteType {\xe2\x86\xb5      id\xe2\x86\xb5      name\xe2\x86\xb5      createdAt\xe2\x86\xb5      updatedAt\xe2\x86\xb5    }\xe2\x86\xb5  }\xe2\x86\xb5}\xe2\x86\xb5",\n    "variables": {"input": {"id": "0c5e3ced-ffa3-4de8-9010-40b67d5bab68"}}\n}\n
Run Code Online (Sandbox Code Playgroud)\n

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

\n

小智 18

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

\n
{\n    "query": "mutation DeleteNote($input: DeleteNoteInput!, $condition: ModelNoteConditionInput) {\xe2\x86\xb5  deleteNote(input: $input, condition: $condition) {\xe2\x86\xb5    id\xe2\x86\xb5    name\xe2\x86\xb5    description\xe2\x86\xb5    image\xe2\x86\xb5    createdAt\xe2\x86\xb5    updatedAt\xe2\x86\xb5    NoteType {\xe2\x86\xb5      id\xe2\x86\xb5      name\xe2\x86\xb5      createdAt\xe2\x86\xb5      updatedAt\xe2\x86\xb5    }\xe2\x86\xb5  }\xe2\x86\xb5}\xe2\x86\xb5",\n    "variables": {"input": {"id": "0c5e3ced-ffa3-4de8-9010-40b67d5bab68", "_version": "_version value of your note object"}}\n}\n
Run Code Online (Sandbox Code Playgroud)\n

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

\n