What I want to do
I have a node that has an outgoing reverse edge. I want to delete this node and also the outgoing edge associated with it. So that when I query the data, the outgoing edges shouldn’t show up in the query response.
What I did
- I added new data in Dgraph, by executing the below mutation-
{
"set": [
{
"name": "Red",
"luckyColour": [
{
"uid": "_:Sham",
"name": "Sham",
"dgraph.type": "Person"
}
],
"dgraph.type": "Colour"
},
{
"name": "Green",
"luckyColour": [
{
"name": "John",
"connectedTo": [
{
"uid": "_:Sham",
"dgraph.type": "Person"
}
],
"dgraph.type": "Person"
}
],
"dgraph.type": "Colour"
}
]
}
- I executed this query to delete the node having the name Sham and all the outgoing edges belonging to this node-
{
delete {
<0x17966> * * .
}
}
According to this https://dgraph.io/docs/mutations/delete/#wildcard-delete, the above mutation should delete the node and all the outgoing edges(including reverse edges) of this node.
The pattern S * * deletes all the known edges out of a node, any reverse edges corresponding to the removed edges, and any indexing for the removed data.
But when I execute this query-
{
result(func:type(Colour)) @recurse(depth:3) {
expand(_all_)
dgraph.type
}
}
I get the below response. In that JSON response, if you check the node with uid= “0x17966”, it still has the “~connectedTo” edge, even though it was deleted by the above query.
{
"result": [
{
"uid": "0x17965",
"name": "Red",
"luckyColour": [
{
"uid": "0x17966",
"~connectedTo": [
{
"uid": "0x17964",
"name": "John",
"dgraph.type": [
"Person"
]
}
]
}
],
"dgraph.type": [
"Colour"
]
},
{
"uid": "0x17967",
"name": "Green",
"luckyColour": [
{
"uid": "0x17964",
"connectedTo": [
{
"uid": "0x17966"
}
],
"name": "John",
"dgraph.type": [
"Person"
]
}
],
"dgraph.type": [
"Colour"
]
}
]
}
Dgraph metadata
This is the schema for the above data-
<connectedTo>: [uid] @reverse .
<dgraph.drop.op>: string .
<dgraph.graphql.p_query>: string @index(sha256) .
<dgraph.graphql.schema>: string .
<dgraph.graphql.xid>: string @index(exact) @upsert .
<luckyColor>: [uid] .
<luckyColour>: [uid] .
<name>: string .
type <Colour> {
name
luckyColour
}
type <Person> {
<~connectedTo>
connectedTo
name
}
type <colour> {
name
luckyColor
}
type <dgraph.graphql> {
dgraph.graphql.schema
dgraph.graphql.xid
}
type <dgraph.graphql.persisted_query> {
dgraph.graphql.p_query
}
Dgraph version- v21.03.0