graphjin icon indicating copy to clipboard operation
graphjin copied to clipboard

CRUD within a DB transaction

Open frederikhors opened this issue 5 years ago • 3 comments

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:

  1. check if the player's buyer has enough money
  2. if not abort operation
  3. if yes, ok, take that money from the buyer's account and deposit it to the owner's account
  4. 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?

frederikhors avatar Jul 02 '20 10:07 frederikhors

You could do this at the Postgres DB level, create a sell_player table with a trigger to do this.

dosco avatar Jul 02 '20 13:07 dosco

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.

frederikhors avatar Jul 06 '20 09:07 frederikhors

I plan on working on docs for a bit this week. Will add a page full of common examples: db schema + config + graphql

dosco avatar Jul 07 '20 01:07 dosco