Unintuitive "LIMIT"?

I have model Post(created, title, owner) with 2 rows:

  1. 2020-04-01, Foo, 0xA
  2. 2020-04-02, Bar, 0xB

I want to find the most recent post by owner 0xA, so here’s my query:

    bla(func: type(Post), orderdesc: created, first: 1) @cascade {
        owner @filter(uid(0xA))
        title
    }

But it doesn’t work! It seems first: 1 takes precedence over owner @filter. If I remove first: 1, it will work, but I’m only interested in one result.

How should my query be?

This is the expected, Root params comes first.

Try this

{
  get as var(func: type(Post)) @cascade {
    owner @filter(uid(0xA)) { uid }
  }
  bla(func: uid(get), orderdesc: created, first: 1)  {
        title
    }
}

You meant:

get as var(func: type(Post)) @cascade { 
    owner @filter(uid(0xA))
    uid
}

Right?

Also, isn’t this inefficient? Like loading all ids and throwing everything but one? (I know only one gets sent over the network, but…)

Nope, the first one is the correct one. You have to add the nested block in the cascade query as far as I know.

If you have millions to billions of nodes, yes it can be.

This was the way to solve the paging issue in my head. As you said it was the issue. Without a way to test on my side, I have to imagine the scenario to give a quick answer. If you test my hypothesis and it succeeds. Nice! Otherwise, I will have to create a scenario or ask you for a sample and test it on my side. It would be the safest and most accurate way.

But on closer examination, it seems that it should support this query. Try also this one.

{
  get as var(func: type(Post), first: 1) @cascade {
    owner @filter(uid(0xA)) { uid }
  }
  bla(func: uid(get), orderdesc: created)  {
        title
    }
}

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.