uid
, which is
assigned randomly. So the ordering, while deterministic, might not be what you
expected.q(func: ..., first: N)
predicate (first: N) { ... }
predicate @filter(...) (first: N) { ... }
N
, first: N
retrieves the first N
results, by sorted or UID
order.
For negative N
, first: N
retrieves the last N
results, by sorted or UID
order. Currently, negative is only supported when no order is applied. To
achieve the effect of a negative with a sort, reverse the order of the sort and
use a positive N
.
Query Example: last two films, by UID order, directed by Steven Spielberg and
the first three genres of those movies, sorted alphabetically by English name.
q(func: ..., offset: N)
predicate (offset: N) { ... }
predicate (first: M, offset: N) { ... }
predicate @filter(...) (offset: N) { ... }
offset: N
the first N
results arenβt returned. Used in combination with
first, first: M, offset: N
skips over N
results and returns the following
M
.
N
results takes time proportional to N
(complexity O(N)
).
In other words, the larger N
, the longer it takes to compute the result set.
Prefer after over offset
.q(func: ..., after: UID)
predicate (first: N, after: UID) { ... }
predicate @filter(...) (first: N, after: UID) { ... }
predicate (after: 0x0, first: N)
,
or just predicate (first: N)
, with subsequent queries of the form
predicate(after: <uid of last entity in last result>, first: N)
.
after
takes constant time (complexity O(1)
). In
other words, no matter how many results are skipped, no extra time adds to
computing the result set. This should be preferred over offset.0x99e44
. The results after Strictly Ballroom can now be obtained with after
.