relatedProducts
Retrieve related products from an opaque product ID.
Last updated:
relatedProducts returns visible recommendations for the specified product. The lookup prioritizes similarity and can complete the result with products from the same category, brand, or available catalog.
Signature
relatedProducts(productId: String!, limit: Int): [ProductSummary!]!Arguments
| Argument | Type | Required | Default | Rule |
|---|---|---|---|---|
productId | String! | Yes | — | Valid opaque product ID. |
limit | Int | No | 8 | Between 1 and 12. |
Obtain productId from the id field returned by product or products, store it as a string, and send it back without parsing or constructing it.
If the reference product does not exist or is not visible in the store, the query returns an empty list.
Return value
The result is a non-null list of ProductSummary values:
| Field | Type | Description |
|---|---|---|
id | String! | Opaque related product ID. |
name | String! | Published name. |
slug | String! | Public slug. |
productType | String! | Product type. |
imageUrl | String! | Primary image. |
price | Decimal! | Current price. |
compareAtPrice | Decimal | Compare-at price, when present. |
variantCount | Int! | Number of variants. |
isAvailable | Boolean! | Current availability. |
totalInventory | Int! | Reported total inventory. |
bundleItemsCount | Int! | Number of bundle components. |
brand | String! | Brand. |
category | String! | Category. |
status | String! | Published status. |
collections | [String!]! | Associated collections. |
tags | [String!]! | Published tags. |
seller | ProductSellerInfo | Seller, when present. |
ProductSellerInfo contains id, name, and slug, all String!.
Query
query RelatedProducts($productId: String!, $limit: Int = 8) {
relatedProducts(productId: $productId, limit: $limit) {
id
name
slug
productType
imageUrl
price
compareAtPrice
variantCount
isAvailable
totalInventory
bundleItemsCount
brand
category
status
collections
tags
seller {
id
name
slug
}
}
}Variables:
{
"productId": "456",
"limit": 4
}The example variable default matches the resolver default. You can omit limit from the variables to request up to eight results.
cURL
curl --request POST "https://storefront.ecomiq.pe/graphql" \
--header "Content-Type: application/json" \
--header "x-Store-Domain: my-store" \
--data-binary '{
"query": "query RelatedProducts($productId: String!, $limit: Int = 8) { relatedProducts(productId: $productId, limit: $limit) { id name slug productType imageUrl price compareAtPrice variantCount isAvailable totalInventory bundleItemsCount brand category status collections tags seller { id name slug } } }",
"variables": { "productId": "456", "limit": 4 }
}'Response
{
"data": {
"relatedProducts": [
{
"id": "789",
"name": "Related mug",
"slug": "related-mug",
"productType": "Product",
"imageUrl": "/related.jpg",
"price": 12,
"compareAtPrice": null,
"variantCount": 1,
"isAvailable": true,
"totalInventory": 2,
"bundleItemsCount": 0,
"brand": "Acme",
"category": "Home",
"status": "Active",
"collections": [],
"tags": [],
"seller": null
}
]
}
}Errors
| Code | Common cause |
|---|---|
BAD_USER_INPUT | productId is not valid or limit is outside 1–12. |
STORE_CONTEXT_REQUIRED | x-Store-Domain did not resolve a store. |
An empty list is not an error: it can mean that the reference product is not visible or no available recommendations were found. See GraphQL errors for envelope handling.