MJBZA
MJBZA

Reputation: 5018

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

I have a simple full-stack amplify app.

Here is my model:

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!
}

I'm trying to delete a Note with the following payload:

{
    "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"}}
}

What I see in the response is the following 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."
        }
    ]
}

The code was working until I tried to add the NoteType! Is there any conflict regarding the foreign-key here?

Upvotes: 8

Views: 6436

Answers (1)

mabahamo
mabahamo

Reputation: 783

When using ConflictResolution you also need to include the _version field.

{
    "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"}}
}

I also noticed that after deleting elements that are using ConflictResolution, they are not immediately deleted from the database. Instead, two flags are being added: _deleted is set to true and _ttl is set to expire the object in 30 days.

Upvotes: 18

Related Questions