Queries
relatedProducts
Products related to another one, from its ID.
relatedProducts returns products similar to the one you pass. It searches by similarity first, then fills in with available products from the same category, the same brand and the rest of the catalog.
relatedProducts(productId: String!, limit: Int): [ProductSummary!]!If you already request the product with product, use its related(limit) field and skip the second request.
Arguments
| Argument | Type | Default | Rule |
|---|---|---|---|
productId | String! | — | The id from product or products. |
limit | Int | 8 | 1 to 12. Out-of-range values are clamped to the nearest bound. |
If the product doesn't exist or isn't published, the list comes back empty.
Returns
A list of ProductSummary, the same type products returns. It includes reviews, with the arguments described in Reviews for each product.
Example
query RelatedProducts($productId: String!, $limit: Int) {
relatedProducts(productId: $productId, limit: $limit) {
id
name
slug
imageUrl
price
compareAtPrice
isAvailable
brand
}
}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) { relatedProducts(productId: $productId, limit: $limit) { id name slug imageUrl price compareAtPrice isAvailable brand } }",
"variables": { "productId": "456", "limit": 4 }
}'{
"data": {
"relatedProducts": [
{
"id": "789",
"name": "Large mug",
"slug": "large-mug",
"imageUrl": "/large-mug.jpg",
"price": 12,
"compareAtPrice": null,
"isAvailable": true,
"brand": "Acme"
}
]
}
}Errors
| Code | Cause |
|---|---|
BAD_USER_INPUT | productId isn't a valid ID. |
STORE_CONTEXT_REQUIRED | x-Store-Domain is missing or doesn't match a store. |
REST equivalent
GET / returns the same list.
Last updated: