Skip to Content
ReferenceStorefrontv0.8.0 API ReferenceConnectionsArticleConnection

ArticleConnection

A connection to a list of Article items, designed to support efficient cursor-based pagination. This connection type provides access to the articles themselves, their edges, pagination metadata, and the total count of articles available.

Connection Structure

{ edges: [ArticleEdge] nodes: [Article] pageInfo: PageInfo! totalCount: Int }

Pagination Arguments

The ArticleConnection supports the following pagination arguments to navigate through the list of articles:

ArgumentTypeDescriptionConstraints
firstIntReturns the first n elements from the list after the cursor specified by after.Must be a positive integer
lastIntReturns the last n elements from the list before the cursor specified by before.Must be a positive integer
afterStringReturns elements after the specified cursor (exclusive).Must be a valid cursor string
beforeStringReturns elements before the specified cursor (exclusive).Must be a valid cursor string

These arguments enable forward and backward pagination using opaque cursors.

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 when paginating forward.
  • hasPreviousPage: Indicates if there are more items when paginating backward.
  • 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 help clients determine navigation possibilities and construct subsequent queries.

Usage Examples

Basic Pagination

Fetch the first 5 articles with their IDs and titles:

{ articles(first: 5) { nodes { id title } pageInfo { hasNextPage endCursor } totalCount } }

Forward Pagination

Fetch the next 5 articles after a given cursor:

{ articles(first: 5, after: "YXJyYXljb25uZWN0aW9uOjQ=") { edges { node { id title } cursor } pageInfo { hasNextPage endCursor } } }

Backward Pagination

Fetch the previous 5 articles before a given cursor:

{ articles(last: 5, before: "YXJyYXljb25uZWN0aW9uOjEw") { edges { node { id title } cursor } pageInfo { hasPreviousPage startCursor } } }

Cursor-based Navigation

Navigate through articles using cursors to fetch pages efficiently:

# Initial request to get the first page and its endCursor { articles(first: 3) { edges { node { id title } cursor } pageInfo { hasNextPage endCursor } } } # Use endCursor from previous response to fetch the next page { articles(first: 3, after: "YXJyYXljb25uZWN0aW9uOjM=") { edges { node { id title } cursor } pageInfo { hasNextPage endCursor } } }

Combined with Filtering

Assuming the articles query supports filtering by category and sorting by publishedDate, combine pagination with these arguments:

{ articles(first: 5, after: "YXJyYXljb25uZWN0aW9uOjU=", filter: { category: "Technology" }, sort: { field: PUBLISHED_DATE, direction: DESC }) { nodes { id title publishedDate category } pageInfo { hasNextPage endCursor } totalCount } }

Note: Filtering and sorting arguments are examples; only use them if supported by the API.

Edge Type

The ArticleEdge type represents a single edge in the connection and contains:

{ node: Article cursor: String! }
  • node: The article item at the edge.
  • cursor: An opaque string used for pagination to identify the position of this edge.

Edges provide the link between the connection and the actual article nodes, enabling cursor-based pagination.

Pagination Best Practices

  • Use first with after for forward pagination and last with before for backward pagination to avoid ambiguous results.
  • Always check pageInfo.hasNextPage and pageInfo.hasPreviousPage before attempting to paginate further.
  • Use the cursors returned in edges.cursor or pageInfo.startCursor / pageInfo.endCursor for reliable navigation.
  • Avoid large page sizes to reduce response times and improve performance.
  • Handle empty results gracefully by checking if nodes or edges arrays are empty.

Performance Considerations

  • Cursor-based pagination is efficient for large datasets as it avoids offset-based scanning.
  • Limit the number of items requested per page to balance response size and user experience.
  • Use filtering and sorting to narrow down results before paginating.
  • Cache cursors when possible to reduce repeated queries.
  • Monitor rate limits when performing frequent paginated queries.
  • [ArticleEdge]: Represents edges in the connection, containing an article node and a cursor.
  • [Article]: The article object type containing article-specific fields.
  • [PageInfo]: Provides pagination metadata such as cursors and page availability.

Notes

  • The API currently requires no authentication for querying articles, but this may change in future versions.
  • Always implement error handling for invalid cursors or out-of-range pagination arguments.
  • When the result set is empty, edges and nodes will be empty arrays, and pageInfo.hasNextPage and pageInfo.hasPreviousPage will be false.
  • For single-page results, pagination arguments like first or last may return fewer items than requested, with pageInfo.hasNextPage and pageInfo.hasPreviousPage set accordingly.
  • Be mindful of rate limiting when making multiple paginated requests in quick succession.
Last updated on