andy mccullough
andy mccullough

Reputation: 9561

AppSync update two tables with one mutation

I am a little confused on the best approach in how to update two tables with on GraphQL mutation, I am using AWS AppSync.

I have an application where I need a User to be able to register for an Event. Given I am using DynamoDB as the database, I had thought about a denormalized data structure for the User and Event tables. I am thinking of storing an array of brief Event details, such as eventID and title in the User table and an array of entrants in the Events table, holding only brief user info, such as userID and name. Firstly, is this a good approach or should I have a third join table to hold these 'relationships'.

If it's OK, I am needing to update both tables during the signUp mutation, but I am struggling to get my head around how to update 2 tables with the one mutation and in turn, one request mapping template.

Am I right in thinking I need to use a Pipeline resolver? Or is there another way to do this?

Upvotes: 0

Views: 1385

Answers (1)

Ionut Trestian
Ionut Trestian

Reputation: 5751

There are multiple options for this:

  1. AppSync supports BatchWrite operations to update multiple DynamoDb tables at the same time
  2. AppSync supports DynamoDb transactions to update multiple DynamoDb tables transactionally at the same time
  3. Pipeline resolvers

Upvotes: 2

Related Questions