Skip to main content
Version: 3.0

Paginating large result sets

It is quite common to have to paginate over large result sets.

GraphQLite offers a simple way to do that using Porpaginas.

Porpaginas is a set of PHP interfaces that can be implemented by result iterators. It comes with a native support for PHP arrays, Doctrine and TDBM.

Usage‚Äč

In your query, simply return a class that implements Porpaginas\Result:

class MyController
{
/**
* @Query
* @return Product[]
*/
public function products(): Porpaginas\Result
{
// Some code that returns a list of products

// If you are using Doctrine, something like:
return new Porpaginas\ORMQueryResult($doctrineQuery);
}
}

Notice that:

  • the method return type MUST BE Porpaginas\Result or a class implementing Porpaginas\Result
  • you MUST add a @return statement to help GraphQLite find the type of the list

Once this is done, you can paginate directly from your GraphQL query:

products {
items(limit: 10, offset: 20) {
id
name
}
count
}

Results are wrapped into an item field. You can use the "limit" and "offset" parameters to apply pagination automatically.

The "count" field returns the total count of items.