Magidoc

Pagination

Many queries in the Cloudshelf API return a list of items, and these lists can be paginated.

Pagination is an important feature in any modern API as it allows the API to respond quickly with only a small subset of the data held instead of huge amounts.

When requests data, you can specify how many items you want to receive, and which page of the results you want to receive, this is handled by cursors.

When you receive data this will be in the form of a PaginatedPayload object.

Requesting Data

#

All pagination fields in the GraphQL API are optional. If you do not specify a value, our default values will be used.

Where pagination is possible the following fields will always be present:

  • after - The cursor of the item you want to offset from for forward pagination
  • before - The cursor of the item you want to offset from for backward pagination
  • first - The maximum number of items you want to receive in forwards pagination
  • last - The maximum number of items you want to receive in backwards pagination
  • sortBy - A field to sort the results by in either ascending or descending order

Receiving Data

#

When you receive data from a paginated query, it will be in the form of a PaginatedPayload object.

This object will contain the following fields:

  • edges - An array of Edge objects.
  • pageInfo - A PageInfo object
  • totalCount - The total number of items available in the API

Edge Object

#

The Edge object contains the following fields:

  • node - The entity that was requested
  • cursor - The cursor of the entity

PageInfo Object

#

The PageInfo object contains the following fields:

  • hasNextPage - Whether there is another page of results after this one
  • hasPreviousPage - Whether there is another page of results before this one
  • startCursor - The cursor of the first item in the current page
  • endCursor - The cursor of the last item in the current page