Hello, is there a way to run “transactional” logic...
# orm-help
p
Hello, is there a way to run “transactional” logic in Prisma? For instance, I want my GraphQL API to create a post, create a welcome comment, and subscribe the user to the post. Assuming that results 3 Prisma calls, is there a way to ensure the atomicity thereof, so if one call fails the previous get rolled back or not committed in the first place?
t
Nested mutations are executed transactionally
p
Thank you. What if the mutations are not related at all, how do I then nest them?
t
Short answer: it isn't implemented
n
p
Thank you Nilan, I have seen this, and indeed, what I’m asking about is what Søren calls “transactional guarantees for multiple mutations”.
n
There is no way to run that yet 🙂 You can think about rollback logic in your GraphQL Server, or sending mutations one after another.
l
Transactions were a huge help in Absinthe / Elixir (especially with pattern matching the errors, so simple!). With Prisma/Yoga, I'm only writing rollback logic where there's a possible chance of failure. In your scenario (new post, welcome comment, subscription), there's little chance to no chance of it failing. You're taking the proper approach, but I've found that hand rolling rollback logic on every mutation chain will prevent me from shipping until 2023 🙂
😂 1
m
is there any roadmap for transactions? @nilan we’re interested in Prisma for production, but will have to wait until transactions are supported. We can’t risk debiting and crediting financial accounts without the protection of transactions.