Pagination

Shopsys Framework Frontend API uses pagination inspired by Relay cursor connection

Every paginated entity uses connection with information about current page and paginated entities. For more information please see the specification

Usage

If you want to get eg. paginated products you can use products query.

{
  products{}
}

This query will return a connection object which consists of pageInfo, edges and totalCount.

pageInfo is object that represents information about current page of pagination that you are on.
edges are array of objects that are generated and represent the products that you get.
totalCount is total number of products available for query. edge need to consist of cursor (pointer to products location) and node (data of given product that you requested).
When you define connection you need to specify what should be the type of node (eg. Product or String)

To get your products you need to simply write query that gets you the data that you need from the node field of edge with first or last parameters:

{
  products (first:10) {
    edges {
      cursor
      node {
        name
        link
        shortDescription
      }
    }
  }
}

// OR

{
  products (last:10) {
    edges {
      cursor
      node {
        name
        link
        shortDescription
      }
    }
  }
}

To get next page you simply need to add the after parameter if you are using first or before of you are using last with cursor of a node

{
  products (first:10, after: "YXJyYXljb25uZWN0aW9uOjk=") {
    edges {
      cursor
      node {
        name
        link
        shortDescription
      }
    }
  }
}

// OR

{
  products (last:10, before: "YXJyYXljb25uZWN0aW9uOjEw") {
    edges {
      cursor
      node {
        name
        link
        shortDescription
      }
    }
  }
}

To order your result add the orderingMode parameter, which is GraphQL enum type ProductOrderingModeEnum. You are not able to use other value than supported values of the specified type. If you want to add more ordering modes, feel free to extend the type in ProductOrderingModeEnum.types.yaml. Default ordering is relevance for search and priority for other queries.

{
  products (orderingMode: NAME_ASC) {
    edges {
      cursor
      node {
        name
        link
        shortDescription
      }
    }
  }
}