DBIx-Class-Schema-GraphQL
view release on metacpan or search on metacpan
lib/DBIx/Class/Schema/GraphQL.pm view on Meta::CPAN
# Default: stable order by PK
$rs = $rs->search(undef, { order_by => [ map { { -asc => $_ } } @pk_cols ] });
}
# Cursor pagination
if (my $cursor_args = $args->{cursor}) {
my $first = $cursor_args->{first} // 10;
my $after = $cursor_args->{after};
if ($after) {
my @decoded = _decode_cursor($after);
if (@pk_cols == 1) {
# Simple: WHERE pk > cursor_val (works for ordered-by-PK default)
$rs = $rs->search({ $pk_cols[0] => { '>' => $decoded[0] } });
}
else {
# Composite PK: fetch everything after decoded position
# by re-applying a compound condition
my %after_cond = map { $pk_cols[$_] => { '>' => $decoded[$_] } }
0 .. $#pk_cols;
$rs = $rs->search(\%after_cond);
}
}
# Fetch one extra to detect hasNextPage
my @rows = $rs->search(undef, { rows => $first + 1 })->all;
my $has_next = @rows > $first;
@rows = @rows[0 .. $first - 1] if $has_next;
( run in 1.248 second using v1.01-cache-2.11-cpan-600a1bdf6e4 )