Reputation: 948
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
Upvotes: 2
Views: 4200
Reputation: 1937
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.
Upvotes: 2
Reputation: 948
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 }
}
Upvotes: 1