WooCommerce Code Reference

PaginationParams
in package

Standard pagination parameters for connection queries.

Because this class carries #[Unroll], whenever it is used as an execute() parameter the builder expands its properties into individual GraphQL arguments.

Table of Contents

DEFAULT_PAGE_SIZE  = 100
Page size used when neither `first` nor `last` is provided.
MAX_PAGE_SIZE  = 100
Maximum number of items a client may request in a single page.
__construct()  : mixed
Constructor.
get_default_page_size()  : int
The page size to use when no explicit `first` or `last` is provided.
validate_args()  : void
Validate pagination limits on a raw args array without constructing a full PaginationParams instance.
validate_limit()  : void
Validate a `first` / `last` argument.

Constants

MAX_PAGE_SIZE

Maximum number of items a client may request in a single page.

public mixed MAX_PAGE_SIZE = 100

Requests with first or last above this value are rejected with an INVALID_ARGUMENT error, matching the behavior of common GraphQL APIs (e.g. GitHub's 100-item cap).

Methods

__construct()

Constructor.

public __construct([int|null $first = null ][, int|null $last = null ][, string|null $after = null ][, string|null $before = null ]) : mixed
Parameters
$first : int|null = null

Return the first N results.

$last : int|null = null

Return the last N results.

$after : string|null = null

Return results after this cursor.

$before : string|null = null

Return results before this cursor.

Tags
throws
InvalidArgumentException

When first or last is negative or exceeds MAX_PAGE_SIZE.

Return values
mixed

get_default_page_size()

The page size to use when no explicit `first` or `last` is provided.

public static get_default_page_size() : int

Exposed as a method (not just the constant) so the default can become configurable — e.g. via a filter or store option — without requiring call-site changes.

Return values
int

validate_args()

Validate pagination limits on a raw args array without constructing a full PaginationParams instance.

public static validate_args(array<string|int, mixed> $args) : void

Intended for call sites that take raw GraphQL args (like nested connection resolvers) and forward them to Connection::slice(). The constructor already runs the same checks for root queries that build a PaginationParams via #[Unroll], so this keeps both paths in sync.

Parameters
$args : array<string|int, mixed>

Raw args with optional first / last keys.

Tags
throws
InvalidArgumentException

When either limit is negative or above MAX_PAGE_SIZE.

Return values
void

validate_limit()

Validate a `first` / `last` argument.

private static validate_limit(string $name, int|null $value) : void
Parameters
$name : string

The argument name, for the error message.

$value : int|null

The value to validate.

Tags
throws
InvalidArgumentException

When the value is out of range.

Return values
void