2
votes

Is there any way of connecting appsync to dynamodb with option to put multiple items at once? I'm asking about dynamodb reuqest mapping.

Let's say we have saveVotes mutation

type Mutation {
    saveVotes(votes: [VoteInput]): [Vote]!
}

How should I design dynamo request template to get each vote saved as separate object in the dynamodb? Each VoteInput has ID. I'm sending 5 VoteInput, and I want to have 5 separate object, with separate ID in the dynamodb. In the AWS docs there are examples just for single putItem which is not enough for me https://docs.aws.amazon.com/appsync/latest/devguide/resolver-mapping-template-reference-dynamodb.html#aws-appsync-resolver-mapping-template-reference-dynamodb-putitem

2
When you execute a single PutItem, does your PutItem operation needs a conditionExpression? If not, then you can use AWS AppSync BatchPutItem operation. There is a tutorial here on how to use it docs.aws.amazon.com/appsync/latest/devguide/…. - Tinou
What's the best way to do this on current date? - Subhendu Kundu

2 Answers

2
votes

You should take a look at using Batch Resolvers at https://docs.aws.amazon.com/appsync/latest/devguide/tutorial-dynamodb-batch.html

As I understand it, you can construct your GraphQL queries to accept a collection of items and then implement the associated resolvers to perform batch operations in the way you describe.

1
votes

So the best solution for me is to make query this way

mutation saveVotes {
  vote1: saveVotes(author: "AUTHORNAME", value: 1 ) { author, value }
  vote2: saveVotes(author: "AUTHORNAME", value: 3 ) { author, value }
}