0

I am trying to write "BatchPutItem" custom resolver, so that I can create multiple items (not more than 25 at a time), which should accept a list of arguments and then perform a batch operation. Here is the code which I have in CusomtResolver:

#set($pdata = [])
#foreach($item in ${ctx.args.input})
    $util.qr($item.put("createdAt", $util.time.nowISO8601()))
    $util.qr($item.put("updatedAt", $util.time.nowISO8601()))
    $util.qr($item.put("__typename", "UserNF"))
    $util.qr($item.put("id", $util.defaultIfNullOrBlank($item.id, $util.autoId())))
    $util.qr($pdata.add($util.dynamodb.toMapValues($item)))
#end

{
    "version" : "2018-05-29",
    "operation" : "BatchPutItem",
    "tables" : {
        "Usertable1-staging": $utils.toJson($pdata)
    }
}

Response in the query console section:

{
  "data": {
    "createBatchUNF": null
  },
  "errors": [
    {
      "path": [
        "createBatchUserNewsFeed"
      ],
      "data": null,
      "errorType": "MappingTemplate",
      "errorInfo": null,
      "locations": [
        {
          "line": 2,
          "column": 3,
          "sourceName": null
        }
      ],
      "message": "Unsupported operation 'BatchPutItem'. Datasource Versioning only supports the following operations (TransactGetItems,PutItem,BatchGetItem,Scan,Query,GetItem,DeleteItem,UpdateItem,Sync)"
    }
  ]
}

And the query is :

mutation MyMutation {
  createBatchUNF(input: [{seen: false, userNFUserId: "userID", userNFPId: "pID", user NFPOwnerId: "ownerID"}]) {
    items {     
      id
      seen
    }
  }
}

Conflict detection is also turned off enter image description here

And when I check cloud logs I found this error:

enter image description here

HackRx
  • 198
  • 2
  • 14

1 Answers1

0

I was able to solve this issue by disabling DataStore for entire API. When we create a new project/backend app using amplify console, and in data tab it asks us to enable data store so that we can start modelling our GraphQL api, that's the reason which enables versioning for the entire API, and it prevents batchWrite to execute. So in order to solve this issue, we can follow these steps: [Note: I am using @aws-amplify/cli]

$ amplify update api
? Please select from one of the below mentioned services: GraphQL
? Select from the options below: Disable DataStore for entire API

And then amplify push This will fix this issue.

Dharman
  • 30,962
  • 25
  • 85
  • 135
HackRx
  • 198
  • 2
  • 14