Is there any way to delete nodes in a mutation where you update other nodes

I am currently writing the backend for my app, it has a screen, where you can add or remove websites. The websites have a webProperty predicate.

44%20pm

Data structure:

          {
            "websiteUserValue": "vespertilian",
            "webProperty": [
              {
                "webPropertyName": "Twitter",
                "uid": "0x191ab"
              }
            ],
            "uid": "0x191b3"
          },

Is there a way when I am updating the list I can add new nodes and delete nodes with the one command?

Currently I believe I have to run a mu.setSetJson to add elements, and a seperate mu.setDeleteJson as part of the same transaction.

It would be nice if I could append metadata and DGraph would just do this as part of one mutation:

Something like this:
where you have a special ___dgraph operator

websites: [
{
   uid: "0x235"
   __dgraph: {delete: {depth: 1}}
}
{
   websiteUserValue: "vespertilian"
   webProperty:  {
     uid: "0x245"
     __dgraph: {validatePredicates: ["webPropertyName"]}
   }
}
]

What do you think?

This expands upon ideas from my last post:

Thanks
Cam

That’s correct.

Mutation is a different from deletion operation. It is possible to merge, but very infeasible in the medium term. It may never be supported for being complex (due to transactions feature) and very simple to handle via client application.

One thing you can do is create a “Deleted” Label via mutation. Thus the node is not actually deleted, but identified as something to be deleted by application. After that you can create a worker to hunt these nodes and then delete them in a single operation.

And your queries you can always add a filter with “@filter(NOT has(Deleted))”.

Giving Nodes a Type https://docs.dgraph.io/howto/#giving-nodes-a-type

2 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.