Download the PHP package wwwision/relay-pagination without Composer
On this page you can find all versions of the php package wwwision/relay-pagination. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download wwwision/relay-pagination
More information about wwwision/relay-pagination
Files in wwwision/relay-pagination
Package relay-pagination
Short Description Simple pagination implementing the Cursor Connections Specification, see https://relay.dev/graphql/connections.htm
License MIT
Informations about the package relay-pagination
Relay Cursor Pagination
Simple pagination implementing the Cursor Connections Specification, see https://relay.dev/graphql/connections.htm
Installation
Install via composer:
composer require wwwision/relay-pagination
Usage
Next page(s)
Every connection contains information about next and previous pages.
To navigate to a succeeding page, you can use the endCursor of the previous connection as input for the after argument:
Backwards navigation
To navigate to a preceeding page, the startCursor can be passed to the last() method likewise:
Reversed order
The ordering of edges is the same whether forward or backward navigation is used (as defined in the specification).
To navigate through results in reversed order, the reversed() method of the Paginator can be used:
Loaders
This package comes with four adapters (aka "loaders"):
ArrayLoader
The ArrayLoader allows to paginate arbitrary arrays.
Note: This loader is mainly meant for testing and debugging purposes and it should not be used for large datasets because the whole array has to be loaded into memory, obviously.
Usage
Note: The specified array can be associative, but the keys will be lost during pagination since the ArrayLoader only works with the array values in order to guarantee deterministic ordering.
CallbackLoader
The CallbackLoader invokes closures to determine pagination results.
Note: This loader is mainly meant for rapid development, testing & debugging purposes. Usually you'd want to create a custom implementation of the Loader interface instead
Usage
DbalLoader
The DbalLoader allows to paginate arbitrary DBAL results.
Note: This loader requires the doctrine/dbal package to be installed:
composer require doctrine/dbal
Usage
OrmLoader
The OrmLoader allows to paginate arbitrary Doctrine ORM results.
Note: This loader requires the doctrine/orm package to be installed:
composer require doctrine/orm
Usage
Convert nodes
A node is the only untyped property in this package since the loaders define the structure & type of nodes.
For the DbalLoader a node is an associative array containing the raw result from the corresponding database row for example.
In order to make it easier to re-use loaders a Node Converter can be specified that is applied to all results before it is returned:
The above example expects the nodes to contain a valid JSON string. The same mechanism can be used in order to convert database results to a dedicated domain model instance:
Examples
See tests folders