GraphQL product quantity in stock
Question
I'm trying to get the stock quantity of my products via graphql, here is my query, but the quantity is obviously not in the schema. Am I wrong? Is there a possibility to get it somehow?
request:
{products(filter: {sku: {like: "024-%"}}) {
total_count
items {
sku, delivery, name
}
}
}
response:
{
"data": {
"products": {
"total_count": 101,
"items": [
{
"sku": "024-0010-1-0004",
"delivery": "0",
"name": "Zeller Keramik Platzset 43 x 30 cm Hahn & Henne"
},
...
}
Solution
It's not possible as of yet and I'm not sure it will be implemented in the future since, usually, on frontend you don't need the exact qty. You can stock_status
or only_x_left_in_stock
. If you need the qty, you need to create a module and extend the products graphql query. There's an example in the vendor/magento/module-catalog-inventory-graph-ql/etc/schema.graphqls module.
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange