1

I want to get the attribute label value along with the id in the Products graphQL query.

like color { id: 12, label: black }, size{ id: 15, label: xl }

Currently, it returns the id only.

How can I extend the current query?

1 Answer 1

0

Try This

query($url: String!) {
  products(filter: { url_key: { eq: $url } }) {
    items {
      id
      sku
      name
      ... on ConfigurableProduct {
        configurable_options {
          id
          attribute_id_v2
          use_default
          attribute_code
          label
          position
          values {
            value_index
            label
            swatch_data {
              __typename
              value
            }
          }
          product_id
        }
        variants {
          attributes {
            label
            code
            value_index
          }
          product {
            id
            name
            sku
            stock_status
            short_description {
              html
            }
            description {
              html
            }
            image {
              url
              label
            }
            small_image {
              url
              label
            }
            media_gallery {
              url
              label
              ... on ProductVideo {
                video_content {
                  media_type
                  video_provider
                  video_url
                  video_title
                  video_description
                  video_metadata
                }
              }
            }
            price_range {
              minimum_price {
                regular_price {
                  value
                  currency
                }
                final_price {
                  value
                  currency
                }
                discount {
                  amount_off
                  percent_off
                }
              }
            }
          }
        }
      }
    }
    total_count
  }
}
3
  • this is for configurable products. I want this data in all simple products too Commented Nov 9, 2021 at 8:51
  • if the product is configurable then it's showing all its variants. Simple product does not have any variant
    – Msquare
    Commented Nov 10, 2021 at 5:57
  • Simple products can also have various attributes with option/value combination. Commented Nov 11, 2022 at 12:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.