amazon-web-servicesgraphqlapollo-clientaws-appsync

AWS AppSync Mutation not Updating Data - What Could be the Issue?


I'm using AWS AppSync to query and create data but now I need to update the objects. I'm using the udpate mutation created by AppSync but it is returning the data without updating. Could you please look into it? It's important!

mutation MyMutation($id: ID = "2023439223", $currency: String = "", $assignedTo: String = "", $amount: String = "") {
  updateZeeepyOrders(input: {amount: $amount, assignedTo: $assignedTo, currency: $currency, id: $id}) {
    id
    amount
    langFrom
  }
}

Here I'm getting the data without being modified-

{
  "data": {
    "updateZeeepyOrders": {
      "id": "2023439223",
      "amount": "0",
      "langFrom": "hindi"
    }
  }
}

Same thing I'm getting when tried on Postman. Could you please suggest what's wrong with this?


Solution

  • The solution is to add the latest _version of your object inside input like this -

    mutation MyMutation($id: ID = "2023439223", $currency: String = "", $assignedTo: String = "", $amount: String = "") {
      updateZeeepyOrders(input: {_version:21, amount: $amount, assignedTo: $assignedTo, currency: $currency, id: $id}) {
        id
        amount
        langFrom
      }
    }
    

    You'll find the object version in your DynamoDB Table.

    I found the solution in one of the github discussions- https://github.com/aws-amplify/amplify-cli/issues/3237#issuecomment-619359322