DQL filter by the value of edge predicate

Hi,
I am trying to filter by the value of the edge predicate.
The simplified schema looks like this:

type <Video> {
	url
	created_by
}

type<User> {
        status
}

<created_by>: uid @reverse .
<status>: int .

I am trying to filter all the Video nodes by created_by but I got an empty response. I know that the ‘created_by’ is of the type uid, but…
Here is my not working attempt:

{
  q(func: type(Video)) @filter(eq(created_by.status, 1)) {
    url
  }
}

I got an empty response.

How to write a query to get all the videos that were created by the user that has status 1?

I think what you want is to start at user and go to video:

{
  q(func: type(User)) @filter(eq(status,1)) {
    ~created_by {
      url
    }
  }
}

however, if you must start at Video for some reason, you can use uid_in()

{
  uservar as var(func: type(User)) @filter(eq(status,1))
  q(func: type(Video)) @filter(uid_in(created_by, uservar)) {
     url
  }
}

At that point you may as well just write it as the single query. Up to you though.

Or you can use @cascade (but be wary of the performance implications thereof wrt pagination)

{
  q(func: type(Video)) @cascade(created_by) {
     url
     created_by @filter(eq(status,1))
  }
}
1 Like

Thank you.