Product Page - All Content

Fetch all available content for a given product identifier.

What we want to build

We want to show a custom set, similar products and matching products on our product page.

With the power of GraphQL we can request not only one type of content but all in one query. That way we can fetch all available content with just one HTTP request.

For the matching products we do not want to show similar products for our current product, only other matching categories. So we will request up to 6 matchingProductClusters and will skip the first one when we render our UI.

GraphQL query and response - id only

To ensure that you show the most recent data in you shop you should only query the product ids and fetch the rest of the data you need for your UI from your own database.

In case you can not make the extra roundtrip you can actually query all the data that is required to render a basic UI. Just consult the GraphQL schema.

query {
  product(id: "8S-DEMO-Polohemd-1") {
    matchingProductClusters(first: 6) {
      edges {
        node {
          products(first: 3) {
            edges {
              node {
                id
              }
            }
          }
        }
      }
    }
    similarProducts(first: 8) {
      edges {
        node {
          id
        }
      }
    }
    customSets {
      edges {
        node {
          id
          title
          description
          images {
            edges {
              node {
                url
              }
            }
          }
          products {
            id
            similarProducts(first: 2) {
              edges {
                node {
                  id
                }
              }
            }
          }
        }
      }
    }
  }
}

Last updated