How to upsert using GraphQL?

@amaster507 Thanks for your response.

I understand there are current limitations in GQL but performing upsert operations should be atomic and are not desired in two steps, otherwise becomes a recipe for introducing inconsistencies in the database if there are two or more similar operations at once.

Yes, I’ve been experimenting with both and can see that a lot of in-between steps are performed by the GQL layer (great job). Hence, I expected the GQL layer to support upsert behaviour as well.

@MichelDiz thanks for addressing this.
I’m not sure if you mean I don’t need a custom DQL for upsert or don’t need upsert in general. My use case is simple, I’m receiving data from an external source and I transform them into Dgraph. If the node does not exist I add them, otherwise, I update them. Simple enough to use the Add and Update queries but I prefer to perform operations like this in an atomic form.

@MichelDiz Can you expand on this? When I use the Add mutation and the node with an @id directive exists, the operation is disallowed. Also, when I use the Update mutation and the node does not exist, then nothing gets updated. What I want is for either case to succeed when upserting.

2 Likes