productGroups
Search for product groups in the catalog.
Query Structure
query {
productGroups(
query: String,
parentId: Int,
first: Int,
after: String,
last: Int,
before: String,
sortKey: String,
reverse: Boolean
) {
edges {
# ProductGroupEdge fields (if any)
}
nodes {
# ProductGroup fields (if any)
}
pageInfo {
hasNextPage
hasPreviousPage
startCursor
endCursor
}
totalCount
}
}
Arguments
Argument | Type | Description | Required | Default Value |
---|---|---|---|---|
query | String | Search query string to filter results | No | None |
parentId | Int | Filter product groups by parent category ID | No | None |
first | Int | Returns the first n elements | No | None |
after | String | Returns elements after the given cursor | No | None |
last | Int | Returns the last n elements | No | None |
before | String | Returns elements before the given cursor | No | None |
sortKey | String | Field to sort by. Available values: title , default | No | None |
reverse | Boolean | Reverse the order of the underlying list | No | false |
Return Type
ProductGroupConnection
A connection to a list of ProductGroup items.
Field | Type | Description | Required |
---|---|---|---|
edges | [ProductGroupEdge] | A list of edges representing product groups | No |
nodes | [ProductGroup] | A list of product group nodes | No |
pageInfo | PageInfo! | Pagination information | Yes |
totalCount | Int | Total number of product groups matching the query | No |
PageInfo
Field | Type | Description | Required |
---|---|---|---|
hasNextPage | Boolean | Indicates if there are more pages after this one | Yes |
hasPreviousPage | Boolean | Indicates if there are pages before this one | Yes |
startCursor | String | Cursor pointing to the start of the current page | Yes |
endCursor | String | Cursor pointing to the end of the current page | Yes |
Examples
Basic Query
query {
productGroups(first: 5) {
nodes {
id
title
}
totalCount
pageInfo {
hasNextPage
endCursor
}
}
}
Advanced Query
query {
productGroups(
query: "summer",
parentId: 123,
first: 10,
sortKey: title,
reverse: true
) {
edges {
node {
id
title
description
}
cursor
}
totalCount
pageInfo {
hasNextPage
hasPreviousPage
startCursor
endCursor
}
}
}
Field Selection
query {
productGroups(first: 3, sortKey: default) {
nodes {
id
title
}
pageInfo {
hasNextPage
endCursor
}
}
}
cURL Example
curl -X POST https://www.mystoreurl.com/graphql/0.8.0 \
-H "Content-Type: application/json" \
-d '{"query":"query { productGroups(first: 5) { nodes { id title } totalCount pageInfo { hasNextPage endCursor } } }"}'
JavaScript Example
async function fetchProductGroups() {
const query = `
query {
productGroups(first: 5) {
nodes {
id
title
}
totalCount
pageInfo {
hasNextPage
endCursor
}
}
}
`;
try {
const response = await fetch('https://www.mystoreurl.com/graphql/0.8.0', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ query }),
});
const result = await response.json();
if (result.errors) {
console.error('GraphQL errors:', result.errors);
return;
}
console.log('Product Groups:', result.data.productGroups.nodes);
console.log('Total Count:', result.data.productGroups.totalCount);
} catch (error) {
console.error('Network or fetch error:', error);
}
}
fetchProductGroups();
Response Format
The response contains a productGroups
object of type ProductGroupConnection
with the following structure:
{
"data": {
"productGroups": {
"edges": [
{
"node": {
"id": 123,
"title": "Summer Collection",
"description": "Seasonal summer products"
},
"cursor": "cursorString"
}
],
"nodes": [
{
"id": 123,
"title": "Summer Collection",
"description": "Seasonal summer products"
}
],
"pageInfo": {
"hasNextPage": true,
"hasPreviousPage": false,
"startCursor": "cursorStart",
"endCursor": "cursorEnd"
},
"totalCount": 50
}
}
}
Error Handling
Error Code | Description | Handling Recommendation |
---|---|---|
BAD_USER_INPUT | Invalid argument values, such as invalid sortKey or non-integer parentId | Validate input before sending the query |
INTERNAL_SERVER_ERROR | Server encountered an unexpected condition | Retry after some delay or contact support |
RATE_LIMIT_EXCEEDED | Client has exceeded the allowed number of requests | Implement exponential backoff and retry |
GRAPHQL_PARSE_FAILED | Malformed GraphQL query syntax | Verify query syntax and structure |
Errors are returned in the errors
array of the GraphQL response. Always check for errors before processing data.
Performance Considerations
- Use pagination arguments (
first
,last
,before
,after
) to limit the size of responses and improve performance. - Avoid requesting large numbers of nodes in a single query.
- Use filtering (
query
,parentId
) and sorting (sortKey
,reverse
) to reduce the dataset size. - Cache query results on the client side when possible to reduce repeated requests.
- Be mindful of rate limits; implement retry logic with backoff on
RATE_LIMIT_EXCEEDED
errors.
Authentication
This API currently does not require authentication. However, authentication requirements may be introduced in future versions. Monitor API updates for any changes to authentication requirements.
Related Types
- ProductGroupConnection: Connection type for paginated product groups.
- ProductGroupEdge: Edge type containing a
node
of typeProductGroup
and acursor
. - ProductGroup: Represents a product group (fields not detailed in source).
- PageInfo: Pagination metadata.
Notes
- The
sortKey
argument accepts only"title"
or"default"
as valid values. - Pagination cursors (
after
,before
) are opaque strings returned inpageInfo
. - The
reverse
argument reverses the order of the results after sorting. - The
query
argument performs a search filter on product groups. - The
parentId
argument filters product groups by their parent category ID. - Always check
pageInfo.hasNextPage
andpageInfo.hasPreviousPage
to implement pagination controls in client applications.
Last updated on