deleteJson to delete a Node does not delete it

I think I see the underlying issue of the OP if you decide to continue with DQL and the dgraph-js-http client.

From the docs:

If no predicates are specified, then all of the node’s known outbound edges (to other nodes and to literal values) are deleted (corresponding to deleting S * * ). The predicates to delete are derived using the type system. Refer to the RDF format documentation and the section on the type system for more information

(Emphasis Added)

In this tutorial, Dgraph is ran in a “schemaless” manner. The schema is not predefined but is assumed based on the received data. Also there are no types set for the nodes that are created.

Ideally should have been:

setJson: {
  uid: "_:newTodo",
  "dgraph.type": "Todo",
  is_todo: true,
  title,
  completed: false
},

But I think the types would also need to be defined with their fields, I may be wrong about this part. Without defining the Dgraph.type on the nodes deletes in the manner of S * * will not be deleted. So instead the deletes would have to be in the form of S P * or S P O to work:

deleteJson: {
  uid: todo.uid
  is_todo: null,
  completed: null
},

Overall, if you are new to Dgraph and are working with React/Next/Vue frontends I would HIGHLY recommend to use GraphQL instead. That would have solved 100% of this OP because with GraphQL the type system is enforced and a predefined schema is required.

1 Like