graphjin
graphjin copied to clipboard
CRUD within a DB transaction
I'm wondering how to solve this problem with SuperGraph.
Now I have an endpoint like this:
type Mutation {
sellPlayer(player: PlayerInput!): Player!
}
The business logic here is:
- check if the player's buyer has enough money
- if not abort operation
- if yes, ok, take that money from the buyer's account and deposit it to the owner's account
- do this in a DB transaction
Now with SuperGraph is there a way to achieve this?
It's still CRUD, just a little different, don't you think?
You could do this at the Postgres DB level, create a sell_player table with a trigger to do this.
Good idea. Thanks for the tip.
Can you please re-open this until some of us find time to document this process in the docs?
So other people can also benefit and/or contribute.
I plan on working on docs for a bit this week. Will add a page full of common examples: db schema + config + graphql