Prisma1: Atomic GraphQL mutations

Created on 19 Dec 2016  路  7Comments  路  Source: prisma/prisma1

Some scenarios required multiple mutations to be executed atomically. This should be implemented using GraphQL directives.

Most helpful comment

I built a simple library, that adds those mutex functions to the graphcool-lib library:
https://github.com/AgarthaSolutions/graphcool-mutex

All 7 comments

:1st_place_medal: Would be a wonderful addition! Would clean up some controllers in my app for sure :D

Thanks for the feedback @emolr! What is your current approach to handle this?

Hey! Sorry for the late response didn't see your question @marktani.

If i understand it correctly, It could help me when i'm creating an account, adding the logged in user to the account and creating a campaign and creating the relation to the newly created account at the same time.

So it could be something like a createAndAddUserToAccount directive where mutation 1 is: createAccount, and mutation 2: addUserToAccountUsers inheriting the created Account.id.

Is it something like this Atomic GraphQL mutations means?
Because now i create Account, wait for success then receive the id of the Account, then add the User to the Account, but "manually" from my client

You can "fake" this (in a very hacky way) but introducing a mutation that wraps a set of actions as its input argument, along with the remaining data. We are using that approach while we look into making mutations directly atomic.

If there is a mutex function in the graph cool library , we can make our own atomic functions in the request pipeline.

As an example

mutex.lock("some_atomic_mutation");
... run queries and atomic updates ...
mutex.unlock("some_atomic_mutation");

I built a simple library, that adds those mutex functions to the graphcool-lib library:
https://github.com/AgarthaSolutions/graphcool-mutex

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jannone picture jannone  路  3Comments

AlessandroAnnini picture AlessandroAnnini  路  3Comments

ragnorc picture ragnorc  路  3Comments

marktani picture marktani  路  3Comments

schickling picture schickling  路  3Comments