0
votes

I am new to AWS and I am trying to update a value in the DynamoDB using query and it is returning me below error

The provided key element does not match the schema

The code done and the response is listed below

Error Response

    {
  "data": {
    "updateIsRead": null
  },
  "errors": [
    {
      "path": [
        "updateIsRead"
      ],
      "data": null,
      "errorType": "DynamoDB:AmazonDynamoDBException",
      "errorInfo": null,
      "locations": [
        {
          "line": 30,
          "column": 3
        }
      ],
      "message": "The provided key element does not match the schema (Service: AmazonDynamoDBv2; Status Code: 400; Error Code: ValidationException; Request ID: 7ELPDK32SD0K9TGT31J03ANHVNVV4KQNSO5AEMVJF66Q9ASUAAJG)"
    }
  ]
}

Query

//I want to update the isRead key value to true of below messageId

    mutation UpdateISRead{
      updateIsRead(input:{messageId:"3253b0b4-6645-4df2-952f-93694cc70af3"}){
        messageId
      }
    }

Schema

type Mutation {
   updateIsRead(input: MessageIDInput!): MessageRecipient
}

type MessageRecipient {
    messageId: ID!
    messageRecipientId: String!
    receiverId: String!
    isRead: Boolean!
}

Resolver for Mutation.updateIsRead

{
    "version" : "2017-02-28",
    "operation" : "UpdateItem",
    "key" : {
         "messageId" : $util.dynamodb.toDynamoDBJson($ctx.args.messageId)
    },
 "update" : {
         "expression" : "SET #fieldName = :fieldValue",
         "expressionNames" : {
              "#fieldName" : "isRead"
         },
         "expressionValues" : {
            ":fieldValue" : { "BOOL" : true }
         }
        }
}

Any help in this is much appreciated. Thanks in Advance.

1
What are your partition key and sort key attributes and types? To find out go into DynamoDB console, click Tables on the left hand menu, and you should see it displayed on the right.F_SO_K

1 Answers

0
votes

If someone is looking for an answer for the above issue, I resolve it by changing below

  "messageId" : $util.dynamodb.toDynamoDBJson($ctx.args.messageId)

to

  "messageId" : $util.dynamodb.toDynamoDBJson($ctx.args.input.messageId)

We need to take the sent data as an input so after adding $ctx.args.input.messageId it resolved my issue.