# How do I expand all non-uid predicates, plus some specific edges?

**URL:** <https://discuss.dgraph.io/t/how-do-i-expand-all-non-uid-predicates-plus-some-specific-edges/16129>\
**Category:** Dgraph\
**Tags:** kind:question\
**Created:** [November 23, 2021, 4:42pm UTC](https://discuss.dgraph.io/t/how-do-i-expand-all-non-uid-predicates-plus-some-specific-edges/16129 "2021-11-23T16:42:36Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![gc\_snglr](https://avatars.discourse-cdn.com/v4/letter/g/ebca7d/32.png) [@gc\_snglr](https://discuss.dgraph.io/u/gc_snglr)\
**Post date:** [November 23, 2021, 4:42pm UTC](https://discuss.dgraph.io/t/how-do-i-expand-all-non-uid-predicates-plus-some-specific-edges/16129/1 "2021-11-23T16:42:36Z")

</div>

## What I want to do

I would like to get all the non-uid predicates, and expand some specific edges. Say, for example, that on the example data from the docs I would like to get all the data about directors named Steve, as well as a list of their respective films. This seems to be a similar problem as [this Github issue](https://github.com/dgraph-io/dgraph/issues/1652), but the solution outlined there doesn’t quite do what I need.

## What I did

The thing I tried first was

```auto
{
  me(func: allofterms(name@en, "Steven")) {
    expand(_all_)
    director.film {
      expand(_all_)
    }
  }
}

```

However, this returns the error `Repeated subgraph: [director.film] while using expand()`. The Github issue mentioned above suggests this as an alternative (slightly adapted for the example):

```auto
{
  steven as var(func: allofterms(name@en, "Steven"))
  directors(func: uid(steven)) {
    expand(_all_)
  }
  films(func: uid(steven)) {
    director.film {
      expand(_all_)
    }
  }
}

```

However, what I don’t understand about this solution is how to match the director to the film, since this query returns the two requested things in separate entries. This is not addressed in the Github issue.

## Dgraph metadata

> **dgraph version**
>
> Dgraph version : v21.03.0  
> Dgraph codename : rocket  
> Dgraph SHA-256 : b4e4c77011e2938e9da197395dbce91d0c6ebb83d383b190f5b70201836a773f  
> Commit SHA-1 : a77bbe8ae  
> Commit timestamp : 2021-04-07 21:36:38 +0530  
> Branch : HEAD  
> Go version : go1.16.2  
> jemalloc enabled : true

---

<div class="post-metadata">

**Author:** ![MichelDiz](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/micheldiz/32/11873_2.png) [@MichelDiz](https://discuss.dgraph.io/u/MichelDiz)\
**Post date:** [November 23, 2021, 6:15pm UTC](https://discuss.dgraph.io/t/how-do-i-expand-all-non-uid-predicates-plus-some-specific-edges/16129/2 "2021-11-23T18:15:17Z")

</div>

> [@gc\_snglr](#):
>
> The thing I tried first was

If you have a well defined Schema, you can do this

```auto
{
  me(func: allofterms(name@en, "Steven")) {
    expand(_all_) {
      expand(_all_)
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![gc\_snglr](https://avatars.discourse-cdn.com/v4/letter/g/ebca7d/32.png) [@gc\_snglr](https://discuss.dgraph.io/u/gc_snglr)\
**Post date:** [November 24, 2021, 8:15am UTC](https://discuss.dgraph.io/t/how-do-i-expand-all-non-uid-predicates-plus-some-specific-edges/16129/3 "2021-11-24T08:15:52Z")

</div>

> [@MichelDiz](#):
>
> If you have a well defined Schema, you can do this
> 
> ```auto
> {
> me(func: allofterms(name@en, "Steven")) {
> expand(_all_) {
> expand(_all_)
> }
> }
> }
> 
> ```

The problem with that is that it follows _all_ the edges. In my case that would return much more data than I want, and would require me filtering the output afterwards.

---

<div class="post-metadata">

**Author:** ![amaster507](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/amaster507/32/4123_2.png) [@amaster507](https://discuss.dgraph.io/u/amaster507)\
**Post date:** [November 24, 2021, 3:35pm UTC](https://discuss.dgraph.io/t/how-do-i-expand-all-non-uid-predicates-plus-some-specific-edges/16129/4 "2021-11-24T15:35:26Z")

</div>

I think the problem with the request is that everything is the same kind of edge to the query. You want all “predicates” (string|int|float|etc.) plus a few specific “edges” (uid) but DQL doesn’t know what predicates (S.P.O. context) are “predicates” and which ones are “edges”.

This is confusing to say because edge and predicate are often used interchangeably by Dgraph.

---

<div class="post-metadata">

**Author:** ![MichelDiz](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/micheldiz/32/11873_2.png) [@MichelDiz](https://discuss.dgraph.io/u/MichelDiz)\
**Post date:** [November 24, 2021, 4:25pm UTC](https://discuss.dgraph.io/t/how-do-i-expand-all-non-uid-predicates-plus-some-specific-edges/16129/5 "2021-11-24T16:25:41Z")

</div>

If you wanna return just predicates/values/data you could create a fake type and use like that

```auto
expand(myFakeType)

```

This can be used in other situations too.

---

<div class="post-metadata">

**Author:** ![amaster507](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/amaster507/32/4123_2.png) [@amaster507](https://discuss.dgraph.io/u/amaster507)\
**Post date:** [November 25, 2021, 12:18am UTC](https://discuss.dgraph.io/t/how-do-i-expand-all-non-uid-predicates-plus-some-specific-edges/16129/6 "2021-11-25T00:18:04Z")

</div>

but the `myFakeType` would have to be pre-defined in the DQL schema correct? Would the node have to have this type or because you explicitly expand with it, it does not check that the node has the type and it just looks for the fields.

---

<div class="post-metadata">

**Author:** ![MichelDiz](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/micheldiz/32/11873_2.png) [@MichelDiz](https://discuss.dgraph.io/u/MichelDiz)\
**Post date:** [November 25, 2021, 2:04pm UTC](https://discuss.dgraph.io/t/how-do-i-expand-all-non-uid-predicates-plus-some-specific-edges/16129/7 "2021-11-25T14:04:31Z")

</div>

It need to be created in the Schema. After that you can use it anywhere with expand()

---

<div class="post-metadata">

**Author:** ![gc\_snglr](https://avatars.discourse-cdn.com/v4/letter/g/ebca7d/32.png) [@gc\_snglr](https://discuss.dgraph.io/u/gc_snglr)\
**Post date:** [November 29, 2021, 3:38pm UTC](https://discuss.dgraph.io/t/how-do-i-expand-all-non-uid-predicates-plus-some-specific-edges/16129/8 "2021-11-29T15:38:38Z")

</div>

Oh, that is interesting, good to know! Thanks @amaster507 and @MichelDiz for the input. Sadly it still doesn’t quite solve my specific problem completely. This is because in my case I don’t know necessarily what type the first node has and, therefore, which fields it has. Therefore I really want to use expand(_all_) for the non-uid fields. For now I went with the expand(_all_) { expand(_all_) } and filter manually approach.

---

<div class="post-metadata">

**Author:** ![MichelDiz](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/micheldiz/32/11873_2.png) [@MichelDiz](https://discuss.dgraph.io/u/MichelDiz)\
**Post date:** [November 29, 2021, 5:17pm UTC](https://discuss.dgraph.io/t/how-do-i-expand-all-non-uid-predicates-plus-some-specific-edges/16129/9 "2021-11-29T17:17:06Z")

</div>

No problem, create a fake type with all possible predicates and edges. The one that doesn’t exist will be ignored.
