0

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?

andy mccullough
  • 9,070
  • 6
  • 32
  • 55

1 Answers1

2

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
Ionut Trestian
  • 5,473
  • 2
  • 20
  • 29
  • im now evening considering that my db structure may not be the correct way to manage the many to many relationship, and starting to look into the adjacency list pattern - https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/bp-adjacency-graphs.html but now im really torn on the best approach :( – andy mccullough Apr 30 '20 at 15:48
  • Have you tried using Amplify? Amplify auto-generates relationships such as these based on annotations in the schema? – Ionut Trestian Apr 30 '20 at 16:03
  • I would say that you can also use something like this: mutation myMutation { createEvent(1) createUser(2) } if you can pass parameters for both mutations from the outside (meaning that createUser mutation does not need output of createEvent mutation). @IonutTrestian - do you think that this is also OK? I am interested if it would not cause something like dirty writes, etc. For me it seems to be OK (at the moment), I am just looking for another pair of eyes – Stefan Majiros Feb 15 '22 at 10:00