Fulfillment_service and inventory_management attribute of a product variant?

In rest api, the product variant returns the above attribute, in our app, we only update the inventory if inventory_management=shopify and fulfilment_service=manual

So in graphql, I have a productVariant id, how to query the above information?

Thanks

Hi,

So for inventory_management=shopify, you can use the inventoryItem.tracked field that’s on productVariant, and for fulfillmentService you’d include inventoryLevels in your query, so it would look something like:

query GetProductVariantDetails {
  productVariant(id: "gid://shopify/ProductVariant/43729076") {
    inventoryItem {
      tracked # Indicates if inventory is managed by Shopify
    }
    inventoryLevels(first: 1) {
      edges {
        node {
          location {
            fulfillmentService {
              type # Indicates the fulfillment service type (e.g., MANUAL, THIRD_PARTY)
            }
          }
        }
      }
    }
  }
}

Thanks for your effort… but not working, this is the query

{“query”: “query getProductVariant($id: ID!) { productVariant(id: $id) { inventoryItem { tracked } inventoryLevels(first: 1) { edges { node { location { fulfillmentService { type } } } } } } }”, “variables”: {“id”: “gid://shopify/ProductVariant/44669986406532”}}

and result

[{“message”:“Field ‘inventoryLevels’ doesn’t exist on type ‘ProductVariant’”,“locations”:[{“line”:1,“column”:109}],“path”:[“query getProductVariant”,“productVariant”,“inventoryLevels”],“extensions”:{“code”:“undefinedField”,“typeName”:“ProductVariant”,“fieldName”:“inventoryLevels”}}]

ok fixed the query:

{“query”: “query getProductVariant($id: ID!) { productVariant(id: $id) { inventoryItem { tracked } inventoryItem { inventoryLevels(first: 1) { edges { node { location { fulfillmentService { type } } } } } } } }”, “variables”: {“id”: “gid://shopify/ProductVariant/44669986406532”}}

But this is the return: (for this product it is managed by shopify and I have not created any fulfillment service, I assume by default it is manual, so it should return something)

{
  "data": {
    "productVariant": {
      "inventoryItem": {
        "tracked": true,
        "inventoryLevels": {
          "edges": [
            {
              "node": {
                "location": {
                  "fulfillmentService": null
                }
              }
            }
          ]
        }
      }
    }
  },
  "extensions": {
    "cost": {
      "requestedQueryCost": 7,
      "actualQueryCost": 7,
      "throttleStatus": {
        "maximumAvailable": 2000.0,
        "currentlyAvailable": 1993,
        "restoreRate": 100.0
      }
    }
  }
}