# Filtering after expand()

**URL:** <https://discuss.dgraph.io/t/filtering-after-expand/9359>\
**Category:** Dgraph\
**Tags:** dgraph\
**Created:** [August 11, 2020, 12:05pm UTC](https://discuss.dgraph.io/t/filtering-after-expand/9359 "2020-08-11T12:05:50Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![Dencomon](https://avatars.discourse-cdn.com/v4/letter/d/e5b9ba/32.png) [@Dencomon](https://discuss.dgraph.io/u/Dencomon)\
**Post date:** [August 13, 2020, 11:29am UTC](https://discuss.dgraph.io/t/filtering-after-expand/9359/3 "2020-08-13T11:29:00Z")

</div>

Hi, it is related to graph database Dgraph. It probably should not be in the GraphQL category, sorry about that. How can I remove this tag?

Here is an example of what I am trying to do (don’t think too much about the logic of my example, I had to change some details in order to be able to post my problem publicly).

Consider these types:

```auto
type Person {
  person.job
  ...
  person.collaborated
}

type Company {
  company.someatr
  ...
  company.produced
  <~person.collaborated>
}

type Food {
  ...
  <~company.produced>
}

type Clothes {
  ...
  <~company.produced>
}

```

(Plus some other types produced by Company and other edges were omitted.)

So the relationships can be drawn like this:

```auto
(Person node) --person.collaborated edge--> (Company node) --company.produced edge--> (Food node)
                                       --company.produced edge--> (Clothes node)
                                       ...

```

Now what my problem is: I sometimes want to be able to do queries like the one below - and use the functionality of Types and @recurse at the same time.

```auto
{
  getProducts(func: eq(person.job, "Something")) @recurse(depth: 3, loop: true) {
    expand(_all_) (first:10)
  }
}

```

But what happens - e.g. the company.produced edge leads to way too many nodes and I need to be able to filter on them based on specific values of their attributes.

If the edge wasn’t part of my Type definition, I am able to do at least this:

```auto
{
  getProducts(func: eq(person.job, "Something")) @recurse(depth: 3, loop: true) {
    expand(_all_) 
    person.collaborated @filter(ge(company.someatr, 5)) 
  }
}

```

But I can’t use this technique on the products of a Company, because “recurse queries require that all predicates are specified in one level”. And also I need these edges in my Type definitions because they are used in other queries…

If edges are part of the Type definition and I try to use a filter like this directly, I get the “expand is only compatible with type filters” error:

```auto
{
  getProducts(func: eq(person.job, "Something")) @recurse(depth: 3, loop: true) {
    expand(_all_) @filter(ge(company.someatr, 5)) 
  }
}

```

Or am I missing something and a query like this can be easily written using variables? So far I was not successful. Thank you very much for your time and help in advance!

---

_[View the full topic](https://discuss.dgraph.io/t/filtering-after-expand/9359)._
