First then Filter in Dgraph Query

There are some steps I would like to achieve:

  1. sort the result by facets(created_at) to get the latest predicate
  2. then, match the result by regular expression.

For example:

{
    directors(func: regexp(name@en, /^Steven Sp.*$/)) {
        name@en
        director.film @facets(orderdesc:created_at)(first:1) @filter(regexp(name@en, /ryan/i)) {
          name@en
        }
    }
}

However, from this code, I couldn’t get the expected result because it was firstly executed to match the result and then retrieve the first one.
Is there any way I could get the latest result and then math it?
Thank you for your help.

Hi. How about using VARs for this. Haven’t tested, but I think sth this should work:

{
    directors(func: regexp(name@en, /^Steven Sp.*$/)) {
        name@en
        MYVAR as director.film @facets(orderdesc:created_at)(first:1)
    }
    queryBlock2(func: uid(MYVAR)) @filter(regexp(name@en, /ryan/i)) {
          name@en
    }
}

I got it.
Your solution is the same as mine. I just wonder if there is any simplified approach.
Thank you for your kind help. :smiling_face_with_three_hearts: