Is there a way to increment a value in DynamoDB through the GraphQL API?
For example: We have two different tables, Posts and Comments as shown below. Every time a new comment was added to the database, I want to increment the commentsCounter inside of the corresponding Post item.
The problem is that I can not just fetch the Posts item, read the value of commentsCounter, add a value of 1 and update the Posts Item again. When multiple comments are added at the same time, the value of commentsCounter would not update correctly.
type Posts @model {
id: ID!
title: String
content: String
comments [Comments] @hasMany(indexName: "byPosts", fields: ["id"])
commentsCounter: Int
}
type Comments @model {
id: ID!
title: String
content: String
postId: ID!
post: Posts @belongsTo(fields: ["postId"])
}
Looking forward to your help! 🙂