Skip to content
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

ArgumentTypeDefaultRule
productIdString!—The id from product or products.
limitInt81 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

RelatedProducts.graphql
query RelatedProducts($productId: String!, $limit: Int) {
  relatedProducts(productId: $productId, limit: $limit) {
    id
    name
    slug
    imageUrl
    price
    compareAtPrice
    isAvailable
    brand
  }
}
Terminal
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 }
  }'
Response
{
  "data": {
    "relatedProducts": [
      {
        "id": "789",
        "name": "Large mug",
        "slug": "large-mug",
        "imageUrl": "/large-mug.jpg",
        "price": 12,
        "compareAtPrice": null,
        "isAvailable": true,
        "brand": "Acme"
      }
    ]
  }
}

Errors

CodeCause
BAD_USER_INPUTproductId isn't a valid ID.
STORE_CONTEXT_REQUIREDx-Store-Domain is missing or doesn't match a store.

REST equivalent

GET /v1/products/{productId}/related returns the same list.

Last updated:

On this page