MichelDiz commented :
It is mentioned in the documentation (I think from @pawanrawal ) that * * O
or * P O
delete are expensive. It costs a lot of performance.
But I found a solution for this. Using the example with Simpson’s family. A detach method with bulk upsert.
As this issue was created before upsert release I couldn’t recommend bulk upsert. But I think this cover it now.
upsert {
query {
v as var(func: eq(name, "Bart")){
p as ~parent_to
}
}
mutation {
delete {
uid(p) <parent_to> uid(v) . #detach method
uid(v) * * .
}
}
}
This way you can “detach” Bart from any parent. But need to use reverse in this case.
Note that this is a case where you delete a Child and need to delete edges coming from relatives. Only in this scenario necessary to do like so. Without reverse is possible, but it complicates the query.
Also I did some similar queries to neo4j docs.
In Neo4j
MATCH ()-[r:RELEASED]-()
DELETE r
In graphql±
upsert {
query {
v as var(func: type(Artist)) @filter(has(RELEASED)){
R as RELEASED
}
}
mutation {
delete {
uid(v) <RELEASED> uid(R) . #This will only delete relationships. Not the nodes.
}
}
}
From parent is very easy.
In Neo4j
MATCH (:Artist)-[r:RELEASED]-(:Album)
DELETE r
In graphql±
In this query you need to verify the relationship between two nodes. It gets a little complicated as you will need to check reverse edges.
upsert {
query {
var(func: type(Artist)) @filter(has(RELEASED)) {
R as RELEASED @filter(has(Album)) {
v as ~RELEASED
# By this I am ensuring that I am deleting a relationship that comes from artist and goes to an album.
}
}
}
mutation {
delete {
uid(v) <RELEASED> uid(R) .
}
}
}
In Neo4j
MATCH (:Artist {Name: "Strapping Young Lad"})-[r:RELEASED]-(:Album {Name: "Heavy as a Really Heavy Thing"})
DELETE r
In graphql±
upsert {
query {
var(func: type(Artist)) @filter(eq(Name, "Strapping Young Lad")) {
R as RELEASED @filter(eq(Name, "Heavy as a Really Heavy Thing")){
v as ~RELEASED
}
}
}
mutation {
delete {
uid(v) <RELEASED> uid(R) .
}
}
}
In Neo4j
MATCH (a:Artist {Name: "Strapping Young Lad"}) DETACH DELETE a
In graphql±
upsert {
query {
a as var(func: type(Artist)) @filter(eq(Name, "Strapping Young Lad"))
}
mutation {
delete {
uid(a) * * .
}
}
}
Note that this query deletes the artist node and its nested relations.