Multiple graphql queries in one transaction "ACID"

I am trying to process a group of data (that should all be committed together, or not at all), is there a way to do that with Slash GraphQL?

I will need to do a few updates to multiple types and ensure it is all or nothing.

1 Like

This is not possible currently. This feature was requested before and there is an RFC for this.

At this stage, we cannot promise any timeline when this feature will be implemented.

The workaround would be to handle these from client side.

You can do this with DQL though. Just not GraphQL.

1 Like

Do you have a guide on how to do this?
It did seem like the Python module pydgraph had this ability but that’s only place I could find any mention of it.

Hey @billybobthorton
Suppose we have the following GraphQL schema with just two types Class and Student:-

type Student {
	name: String
	age: Int
}

type Class {
	standard: Int
	TeacherName: String
}

And now we want to add nodes of Student and Class in a single transaction, then we can’t do it in GraphQL yet. But we can still do it with DQL. For example, if you do a JSON mutation with this data you will get one node of Student and Class each in a single transaction.

 [ {
	"uid": "_:Student1",
  	"Student.name": "Alice",
  	"Student.age": "10",
  	"dgraph.type": "Student"
	},
	{
  	"uid": "_:Class1",
    "Class.standard": "10",
  	"Class.TeacherName": "Bob",
    "dgraph.type": "Class"
	}]

Now coming to the second part that if mutation for any of the type fails then nothing should be committed to our database. To verify this, just change the JSON object for the Class node to the following object and run your cluster in GraphQL mode (it will restrict Dgraph from creating new predicates)

{
  	"uid": "_:Class1",
    "Class.standard": "10",
  	"Class.TeacherName": "Bob",
    "Class.strength": "50",
    "dgraph.type": "Class"
	}

This is an invalid mutation since Class.strength is not an existing predicate in the Dgraph whereas the JSON object Student type is still intact. However, when you execute this whole mutation nothing will be committed to the database. This ensures that either all the data will be committed to the database or none.

The other way to achieve this is to use start_ts same across all the operations. For more information, see here

1 Like

I have managed to do this much, I have been able to add and queries via DQL, my problem is currently modifying existing objects and deletes. I have a thread here I have been banging my head against. I started to do the tutorial which looks like it would answer a lot of my questions, but I had problems with the beginning stages not working (using the Tour to a local Dgraph) and suspect based on my conversations it is a bug with the Tour.

We would be looking into supporting ACID transactions with GraphQL using Transaction RFC in next quarter.

1 Like