I have a type which has an ID. When I get the updates for that type, I don’t know if it is already present in the DB or not. I just want to add it if not present, and update it if present.
But, currently, I’ll have to try add first, then fail, then run update with a filter for that ID. That’s unnecessary work.
Ah, that makes more sense then. Sort of then needing a SQL syntax of INSERT OR UPDATE. The trick here is matching the external ID to a unique key in Dgraph if not using the ID type (my incoming data has a guid formatted id). But Dgraph has no way to force uniqueness on any type other than ID.
I can see how an upsert like this would be useful. Currently, updates check that the node should already exist whereas add only adds it if it doesn’t exist. We could possible provide an optional argument in the updateType mutation to achieve this behavior which would also create the node if it doesn’t exist.
@JatinDevDG could you please note this down in the Community requests for this week so that we could discuss this along with other user issues?