Skip to Content

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

ArgumentTypeDescriptionRequiredDefault Value
queryStringSearch query string to filter resultsNoNone
parentIdIntFilter product groups by parent category IDNoNone
firstIntReturns the first n elementsNoNone
afterStringReturns elements after the given cursorNoNone
lastIntReturns the last n elementsNoNone
beforeStringReturns elements before the given cursorNoNone
sortKeyStringField to sort by. Available values: title, defaultNoNone
reverseBooleanReverse the order of the underlying listNofalse

Return Type

ProductGroupConnection

A connection to a list of ProductGroup items.

FieldTypeDescriptionRequired
edges[ProductGroupEdge]A list of edges representing product groupsNo
nodes[ProductGroup]A list of product group nodesNo
pageInfoPageInfo!Pagination informationYes
totalCountIntTotal number of product groups matching the queryNo

PageInfo

FieldTypeDescriptionRequired
hasNextPageBooleanIndicates if there are more pages after this oneYes
hasPreviousPageBooleanIndicates if there are pages before this oneYes
startCursorStringCursor pointing to the start of the current pageYes
endCursorStringCursor pointing to the end of the current pageYes

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 CodeDescriptionHandling Recommendation
BAD_USER_INPUTInvalid argument values, such as invalid sortKey or non-integer parentIdValidate input before sending the query
INTERNAL_SERVER_ERRORServer encountered an unexpected conditionRetry after some delay or contact support
RATE_LIMIT_EXCEEDEDClient has exceeded the allowed number of requestsImplement exponential backoff and retry
GRAPHQL_PARSE_FAILEDMalformed GraphQL query syntaxVerify 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.

  • ProductGroupConnection: Connection type for paginated product groups.
  • ProductGroupEdge: Edge type containing a node of type ProductGroup and a cursor.
  • 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 in pageInfo.
  • 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 and pageInfo.hasPreviousPage to implement pagination controls in client applications.
Last updated on