Firstly, thank you for creating this example, it's been great for me trying to learn GraphQL.
One query I wrote when thinking about transactions was to check in two pets at the same time. This uncovered a race condition where the code here:
|
await customers.updateOne( |
|
{ username: currentCustomer.username }, |
|
{ |
|
$set: { |
|
checkoutHistory: [checkout, ...currentCustomer.checkoutHistory] |
|
} |
|
} |
|
); |
uses currentCustomer from the context without updating it. So both checkins happen, the first one updates my checkout history to include the first checkout, and the second checkin then overwrites my history as only containing that second checkin. This means my first checkin is lost.