resolvePagination function

ResolvedPagination resolvePagination({
  1. String? after,
  2. String? before,
  3. QueryOrder? order,
  4. int? limit,
})

after and before are exclusive positions. A query takes at most one, and it has to match the direction: after ascending, before descending.

Implementation

ResolvedPagination resolvePagination({
  String? after,
  String? before,
  QueryOrder? order,
  int? limit,
}) {
  if (after != null && before != null) {
    throw ArgumentError('Only one of `after` or `before` may be given');
  }

  final descending = order != null
      ? order == QueryOrder.descending
      : before != null;

  if (after != null && descending) {
    throw ArgumentError('`after` cannot be combined with a descending query');
  }
  if (before != null && !descending) {
    throw ArgumentError('`before` cannot be combined with an ascending query');
  }

  return ResolvedPagination(
    descending: descending,
    after: after,
    before: before,
    limit: limit ?? defaultQueryPageSize,
  );
}