How to Get Upsell Product GraphQL Query Magento 2?

Upsell Product GraphQl query in Magento 2 to retrieve all the upsell items from the given product.

If any product has assigned upsell products from the admin panel and wants to fetch all the upsell items using the GraphQL query, the given post is useful for you.

Detail Description of Product Query GraphQL Magento Check this article first to get a clear idea of Product Query.

Upsell Product GraphQL Query Payload,

{
  products(filter: { sku: { eq: "24-MB01" } }) {
    items {
      id
      name
      upsell_products {
        id
        sku
        stock_status
        short_description {
          html
        }
        url_key
        name
        special_price
        price_range {
          minimum_price {
            final_price {
              value
              currency
            }
          }
          maximum_price {
            final_price {
              value
              currency
            }
          }
        }
      }
    }
  }
}

upsell_products{} field used to retrieve all the upsell items of the given product.

Output:

{
  "data": {
    "products": {
      "items": [
        {
          "id": 1,
          "name": "Joust Duffle Bag",
          "upsell_products": [
            {
              "id": 3,
              "sku": "24-MB03",
              "stock_status": "IN_STOCK",
              "short_description": {
                "html": ""
              },
              "url_key": "crown-summit-backpack",
              "name": "Crown Summit Backpack",
              "special_price": null,
              "price_range": {
                "minimum_price": {
                  "final_price": {
                    "value": 38,
                    "currency": "USD"
                  }
                },
                "maximum_price": {
                  "final_price": {
                    "value": 38,
                    "currency": "USD"
                  }
                }
              }
            },
            {
              "id": 4,
              "sku": "24-MB05",
              "stock_status": "IN_STOCK",
              "short_description": {
                "html": ""
              },
              "url_key": "wayfarer-messenger-bag",
              "name": "Wayfarer Messenger Bag",
              "special_price": null,
              "price_range": {
                "minimum_price": {
                  "final_price": {
                    "value": 45,
                    "currency": "USD"
                  }
                },
                "maximum_price": {
                  "final_price": {
                    "value": 45,
                    "currency": "USD"
                  }
                }
              }
            },
            {
              "id": 5,
              "sku": "24-MB06",
              "stock_status": "IN_STOCK",
              "short_description": {
                "html": ""
              },
              "url_key": "rival-field-messenger",
              "name": "Rival Field Messenger",
              "special_price": null,
              "price_range": {
                "minimum_price": {
                  "final_price": {
                    "value": 45,
                    "currency": "USD"
                  }
                },
                "maximum_price": {
                  "final_price": {
                    "value": 45,
                    "currency": "USD"
                  }
                }
              }
            },
            {
              "id": 6,
              "sku": "24-MB02",
              "stock_status": "IN_STOCK",
              "short_description": {
                "html": ""
              },
              "url_key": "fusion-backpack",
              "name": "Fusion Backpack",
              "special_price": null,
              "price_range": {
                "minimum_price": {
                  "final_price": {
                    "value": 59,
                    "currency": "USD"
                  }
                },
                "maximum_price": {
                  "final_price": {
                    "value": 59,
                    "currency": "USD"
                  }
                }
              }
            },
            {
              "id": 7,
              "sku": "24-UB02",
              "stock_status": "IN_STOCK",
              "short_description": {
                "html": ""
              },
              "url_key": "impulse-duffle",
              "name": "Impulse Duffle",
              "special_price": null,
              "price_range": {
                "minimum_price": {
                  "final_price": {
                    "value": 74,
                    "currency": "USD"
                  }
                },
                "maximum_price": {
                  "final_price": {
                    "value": 74,
                    "currency": "USD"
                  }
                }
              }
            },
            {
              "id": 12,
              "sku": "24-WB03",
              "stock_status": "IN_STOCK",
              "short_description": {
                "html": ""
              },
              "url_key": "driven-backpack",
              "name": "Driven Backpack",
              "special_price": null,
              "price_range": {
                "minimum_price": {
                  "final_price": {
                    "value": 36,
                    "currency": "USD"
                  }
                },
                "maximum_price": {
                  "final_price": {
                    "value": 36,
                    "currency": "USD"
                  }
                }
              }
            },
            {
              "id": 13,
              "sku": "24-WB07",
              "stock_status": "IN_STOCK",
              "short_description": {
                "html": ""
              },
              "url_key": "overnight-duffle",
              "name": "Overnight Duffle",
              "special_price": null,
              "price_range": {
                "minimum_price": {
                  "final_price": {
                    "value": 45,
                    "currency": "USD"
                  }
                },
                "maximum_price": {
                  "final_price": {
                    "value": 45,
                    "currency": "USD"
                  }
                }
              }
            },
            {
              "id": 14,
              "sku": "24-WB04",
              "stock_status": "IN_STOCK",
              "short_description": {
                "html": ""
              },
              "url_key": "push-it-messenger-bag",
              "name": "Push It Messenger Bag",
              "special_price": null,
              "price_range": {
                "minimum_price": {
                  "final_price": {
                    "value": 45,
                    "currency": "USD"
                  }
                },
                "maximum_price": {
                  "final_price": {
                    "value": 45,
                    "currency": "USD"
                  }
                }
              }
            }
          ]
        }
      ]
    }
  }
}

Upsell Product GraphQL output will be all the assigned items from the product.

You can also interested to read GraphQL Query,

  1. How to Get Related Product GraphQL Query Magento 2?
  2. How to Get Cross Sell Product GraphQL Query Magento 2?