ProductGroupConnection
A connection to a list of ProductGroup items, enabling efficient cursor-based pagination over product groups.
Connection Structure
{
edges: [ProductGroupEdge]
nodes: [ProductGroup]
pageInfo: PageInfo!
totalCount: Int
}
Pagination Arguments
The ProductGroupConnection
supports the following pagination arguments to control the slice of data returned:
Argument | Type | Description |
---|---|---|
first | Int | Returns the first n items from the list. Must be a positive integer. |
last | Int | Returns the last n items from the list. Must be a positive integer. |
before | String | Returns items before the specified cursor. Used with last for backward pagination. |
after | String | Returns items after the specified cursor. Used with first for forward pagination. |
Constraints:
first
andlast
cannot be used together in the same query.- When using
before
,last
must be specified. - When using
after
,first
must be specified.
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 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 are essential for implementing cursor-based navigation.
Usage Examples
Basic Pagination
Fetch the first 5 product groups:
{
productGroups(first: 5) {
nodes {
id
name
}
pageInfo {
hasNextPage
endCursor
}
totalCount
}
}
Forward Pagination
Fetch the next 5 product groups after a given cursor:
{
productGroups(first: 5, after: "YXJyYXljb25uZWN0aW9uOjQ=") {
edges {
cursor
node {
id
name
}
}
pageInfo {
hasNextPage
endCursor
}
}
}
Backward Pagination
Fetch the previous 5 product groups before a given cursor:
{
productGroups(last: 5, before: "YXJyYXljb25uZWN0aW9uOjEw") {
edges {
cursor
node {
id
name
}
}
pageInfo {
hasPreviousPage
startCursor
}
}
}
Cursor-based Navigation
Navigate through pages by using cursors returned in pageInfo
and edges
:
{
productGroups(first: 3) {
edges {
cursor
node {
id
name
}
}
pageInfo {
hasNextPage
endCursor
}
}
}
Use the endCursor
from this response as the after
argument in the next query to fetch the following page.
Combined with Filtering
Assuming the productGroups
query supports filtering by category
and sorting by createdAt
(based on actual fields available in the API), combine pagination with filtering:
{
productGroups(first: 10, after: "YXJyYXljb25uZWN0aW9uOjU=" , filter: { category: "electronics" }, sortBy: { field: CREATED_AT, direction: DESC }) {
nodes {
id
name
category
createdAt
}
pageInfo {
hasNextPage
endCursor
}
}
}
Note: Replace filter
and sortBy
with actual supported arguments if available.
Edge Type
The ProductGroupEdge
represents a single edge in the connection and contains:
{
cursor: String!
node: ProductGroup
}
cursor
: An opaque string used for pagination to identify the position of this edge.node
: The actualProductGroup
item at this position.
Edges provide both the item and the cursor needed for cursor-based pagination.
Pagination Best Practices
- Use
first
withafter
for forward pagination andlast
withbefore
for backward pagination to efficiently navigate large datasets. - Always check
pageInfo.hasNextPage
andpageInfo.hasPreviousPage
to determine if more pages exist. - Avoid fetching very large page sizes in a single request to reduce response time and memory usage.
- Use cursors returned from the API rather than constructing your own to ensure consistency.
- Combine pagination with filtering and sorting to reduce the dataset size and improve user experience.
Performance Considerations
- Cursor-based pagination is more performant than offset-based pagination for large datasets because it avoids skipping records.
- Use indexes on fields involved in sorting and filtering to optimize query performance.
- Limit the maximum
first
orlast
values accepted by your client to prevent excessive load. - Monitor query response times and adjust pagination sizes accordingly.
- Cache frequently requested pages where possible to reduce backend load.
Related Types
ProductGroupEdge
ProductGroup
— Represents the individual product group item.PageInfo
— Contains pagination metadata.
Notes
- The API currently requires no authentication for querying
productGroups
, but this may change in future versions. Plan to implement authentication handling in your client. - Handle empty results gracefully by checking if
nodes
oredges
arrays are empty. - When a single page contains all results, both
pageInfo.hasNextPage
andpageInfo.hasPreviousPage
will befalse
. - Implement error handling for invalid cursors or out-of-range pagination arguments to improve robustness.
Endpoint for queries: https://www.mystoreurl.com/graphql/0.8.0/