# Deleting edges

**URL:** <https://discuss.dgraph.io/t/deleting-edges/18963>\
**Category:** Dgraph\
**Tags:** mutation, kind:question\
**Created:** [October 5, 2023, 2:04pm UTC](https://discuss.dgraph.io/t/deleting-edges/18963 "2023-10-05T14:04:29Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![SunSparc](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/sunsparc/32/2532_2.png) [@SunSparc](https://discuss.dgraph.io/u/SunSparc)\
**Post date:** [October 5, 2023, 2:04pm UTC](https://discuss.dgraph.io/t/deleting-edges/18963/1 "2023-10-05T14:04:29Z")

</div>

I am trying to better understand delete mutations, specifically when deleting edges.

Using the following example schema and data:

```auto
type Person {
  first_name
  last_name
  has_spaceships
}
type Spaceship {
  ship_name
  is_owned_by
}
is_owned_by: uid @reverse .
has_spaceships: [uid] .
{
    set {
        _:Person <first_name> "Han" .
        _:Person <last_name> "Solo" .
        _:Person <dgraph.type> "Person" .
        _:Person <has_spaceships> _:Spaceship .

        _:Spaceship <is_owned_by> _:Person .
        _:Spaceship <ship_name> "Falcon" .
        _:Spaceship <dgraph.type> "Spaceship" .
    }
}

```

I can run the following `Person` query:

```auto
{
    query(func: type("Person")) {
        uid
        first_name
        last_name
        dgraph.type
        has_spaceship: ~is_owned_by {
            uid
            ship_name
            dgraph.type
        }
    }
}

```

This will show me `Han` (`0x1`) and an edge connection to his spaceship `Falcon` (`0x2`).

I can run this `Spaceship` query:

```auto
{
    query(func: type("Spaceship")) {
        uid
        ship_name
        dgraph.type
        is_owned_by {
            uid
            first_name
            dgraph.type
        }
    }
}

```

And that will show me the `Falcon` spaceship and an edge connection to the person `Han`.

Now if I delete `Han`, using `S * *`:

```auto
{
    delete {
        <0x1> * * .
    }
}

```

Repeating the `Person` query shows that all the predicates of `0x1` (“Han”) are gone, and the edge still exists.

```auto
uid "0x1"
  has_spaceship {
      uid "0x2"
      ship_name "Falcon"
      dgraph.type ["Spaceship"]
  }

```

If I reset all the data and instead of deleting the `Person` node, I instead delete the `Spaceship` node using `S * *`:

```auto
{
    delete {
        <0x2> * * .
    }
}

```

I can run the `Person` query and the edge will be gone. And of course I can run the `Spaceship` query and the `Falcon` node will be gone.

## Question

I assume that the edge was only deleted when I deleted the `Spaceship` node because of the direction of the edge. The edge was a one-way relation from the `Spaceship` to the `Person`, not from the `Person` to the `Spaceship`. Is my assumption correct?

---

<div class="post-metadata">

**Author:** ![Raphael](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/raphael/32/10075_2.png) [@Raphael](https://discuss.dgraph.io/u/Raphael)\
**Post date:** [October 6, 2023, 2:13pm UTC](https://discuss.dgraph.io/t/deleting-edges/18963/2 "2023-10-06T14:13:53Z")

</div>

```auto
delete {
        <0x1> * * .
    }

```

Instructs Dgraph to delete every predicate it knows about node 0zx01.  
The way it is done is to check ‘dgraph.type’ value for 0x01, which is ‘Person’. Then find the list of potential predicates using the type system.  
It will find first\_name, last\_name, and has\_spaceships and so will delete those predicates for this node.  
As you saw it will not delete the predicate “is\_owned\_by” which is by the way on node 0x02.

[GraphQL and DQL schemas - GraphQL dql](https://dgraph.io/docs/graphql-dql/graphql-dql-schema/) provides info about the DQL Type system,  
You can declare the reverse in Person using the angle bracket notation

```auto
type Person {
  <~is_owned_by>
}

```

In fact in your schema you declared a predicate has\_spaceships but you can use directly ~is\_owned\_by, which you do in the query `has_spaceship: ~is_owned_by`

Declaring \<~is\_owned\_by\> in the Person type will make **expand(all)** and **delete** work.
