Pagination in Graffy is implemented using range keys, which are objects with one or more of the range properties below.

These properties may be combined in various ways:

In the result graph, each child has a key that mirrors the original query, but with the range properties replaced with the cursor:

Range keys may also have other properties that specify filters, sort order etc. These must be echoed back in the result graph’s keys.

For example. let’s make a query for the first 2 users, ordered by their creation time.

Note that $order is not a range property, but this is a conventional property name used by Graffy storage modules.


Keys in the result will have $first replaced with $cursor.

{
  user: [
    {
      $key: {
        $order: 'createTime',
        $cursor: 1684939475
      },
      name: 'Alice'
    },
    {
      $key: {
        $order: 'createTime',
        $cursor: 1684984752
      },
      name: 'Bob'
    },
  ]
}
{
  user: {
    $key: {
      $first: 2,
      $order: 'createTime'
    },
    name: true
  }
}

The result.user array will three additional properties $key, $next and $prev.

These contain range keys to re-fetch this page of results or to get the next or previous page of results, respectively.

$prev or $next may be null if this is the first or last page of results, respectively.