Skip to Content

PreviousPriceConnection

A connection to a list of PreviousPrice items. This type supports cursor-based pagination to efficiently navigate through large sets of previous price records associated with a product variant.

Connection Structure

{ edges: [PreviousPriceEdge] nodes: [PreviousPrice] pageInfo: PageInfo totalCount: Int }

Pagination Arguments

The PreviousPriceConnection supports the following pagination arguments to control the size and direction of the data returned:

ArgumentTypeDescription
firstIntReturns the first n elements from the list. Use for forward pagination.
lastIntReturns the last n elements from the list. Use for backward pagination.
beforeStringReturns elements before the specified cursor. Used with last for backward pagination.
afterStringReturns elements after the specified cursor. Used with first for forward pagination.

Constraints:

  • first and last must be positive integers.
  • before and after must be valid opaque cursors returned by the API.
  • Combining first with before or last with after is invalid and will result in errors.

PageInfo Structure

The pageInfo field provides metadata about the current page of results:

{ hasNextPage: Boolean hasPreviousPage: Boolean startCursor: String endCursor: String }
  • hasNextPage: Indicates if there are more items after the current page.
  • hasPreviousPage: Indicates if there are more items before the current page.
  • startCursor: The cursor corresponding to the first item in the current page.
  • endCursor: The cursor corresponding to the last item in the current page.

These fields enable clients to implement efficient cursor-based navigation.

Usage Examples

Basic Pagination

Fetch the first 5 previous prices for a product variant:

{ productVariant(id: 12345) { previousPrices(first: 5) { nodes { id price effectiveDate } totalCount pageInfo { hasNextPage endCursor } } } }

Forward Pagination

Fetch the next 5 previous prices after a given cursor:

{ productVariant(id: 12345) { previousPrices(first: 5, after: "YXJyYXljb25uZWN0aW9uOjQ=") { edges { node { id price effectiveDate } cursor } pageInfo { hasNextPage endCursor } } } }

Backward Pagination

Fetch the last 5 previous prices before a given cursor:

{ productVariant(id: 12345) { previousPrices(last: 5, before: "YXJyYXljb25uZWN0aW9uOjEw") { edges { node { id price effectiveDate } cursor } pageInfo { hasPreviousPage startCursor } } } }

Cursor-based Navigation

Navigate through pages efficiently by using cursors from pageInfo:

# Initial request { productVariant(id: 12345) { previousPrices(first: 3) { edges { node { id price } cursor } pageInfo { hasNextPage endCursor } } } } # Subsequent request using endCursor { productVariant(id: 12345) { previousPrices(first: 3, after: "YXJyYXljb25uZWN0aW9uOjM=") { edges { node { id price } cursor } pageInfo { hasNextPage endCursor } } } }

Combined with Filtering

While PreviousPriceConnection does not define explicit filtering arguments, it can be combined with filtering on the parent ProductVariant or other query parameters. For example, fetching previous prices for a specific product variant filtered by variant ID:

{ productVariant(id: 12345) { previousPrices(first: 10) { nodes { id price effectiveDate } pageInfo { hasNextPage endCursor } } } }

Sorting is handled by the API’s default behavior or by the parent query parameters, as no explicit sorting arguments are defined on PreviousPriceConnection.

Edge Type

The PreviousPriceEdge type represents an edge in the connection and contains:

  • node: The PreviousPrice item.
  • cursor: An opaque string used for pagination.

Example structure:

{ node: PreviousPrice cursor: String }

The edge connects the PreviousPrice nodes to the pagination mechanism, allowing clients to paginate through the list using cursors.

Pagination Best Practices

  • Use first with after for forward pagination to load subsequent pages.
  • Use last with before for backward pagination to load previous pages.
  • Always check pageInfo.hasNextPage and pageInfo.hasPreviousPage before attempting to paginate further.
  • Avoid large page sizes to reduce response time and improve performance.
  • Use cursors returned by the API as opaque tokens; do not attempt to decode or generate them.
  • Handle empty results gracefully by checking if nodes or edges arrays are empty.
  • Combine pagination with filtering on parent objects to reduce the dataset size when possible.

Performance Considerations

  • Cursor-based pagination is efficient for large datasets as it avoids offset-based limitations.
  • Limiting the number of items per page (first or last) reduces server load and network bandwidth.
  • Avoid deep pagination (very large offsets) as it may impact performance.
  • Use the totalCount field sparingly, as counting large datasets can be expensive on the server.
  • Cache cursors client-side to enable smooth user experience during navigation.

Notes

  • The API currently requires no authentication for querying PreviousPriceConnection, but this may change in future versions.
  • Always validate pagination arguments to prevent errors.
  • Handle error responses gracefully, especially when invalid cursors or argument combinations are used.
  • Use the endpoint https://www.mystoreurl.com/graphql/0.8.0/ for all queries involving pagination.

This documentation aims to help developers of all skill levels implement efficient and reliable pagination when working with previous price data in the API.

Last updated on