inventorySetQuantities bug? quantityAfterChange = null

API versoin 2025-04

Is this a bug that quantityAfterChange is null

mutation InventorySetQuantities($input: InventorySetQuantitiesInput!) {
  inventorySetQuantities(input: $input) {
    inventoryAdjustmentGroup { #defines the properties that are returned. Note it is not possible to limit getting both OnHand and Availble inventory types in the return so need to filter out on our end if needed.
      id
      createdAt
      reason
      changes {
        item {
            id
        }
        name        
        delta
        quantityAfterChange
      }
    }
    userErrors {
      field
      message
    }
  }
}

{
  "input": {
    "name": "on_hand",
    "reason": "correction", 
    "ignoreCompareQuantity": true,
    "quantities": [
      {
        "inventoryItemId": "gid://shopify/InventoryItem/41711590080582",
        "locationId": "gid://shopify/Location/{{location_id}}",
        "quantity": 35
      },
      {
        "inventoryItemId": "gid://shopify/InventoryItem/34431475449926",
        "locationId": "gid://shopify/Location/{{location_id}}",
        "quantity": 18
      }
    ]
  }
}

Result:

{
    "data": {
        "inventorySetQuantities": {
            "inventoryAdjustmentGroup": {
                "id": "gid://shopify/InventoryAdjustmentGroup/20783537684550",
                "createdAt": "2025-05-06T20:09:32Z",
                "reason": "correction",
                "changes": [
                    {
                        "item": {
                            "id": "gid://shopify/InventoryItem/41711590080582"
                        },
                        "name": "available",
                        "delta": 3,
                        "quantityAfterChange": null
                    },
                    {
                        "item": {
                            "id": "gid://shopify/InventoryItem/34431475449926"
                        },
                        "name": "available",
                        "delta": 2,
                        "quantityAfterChange": null
                    },
                    {
                        "item": {
                            "id": "gid://shopify/InventoryItem/41711590080582"
                        },
                        "name": "on_hand",
                        "delta": 3,
                        "quantityAfterChange": null
                    },
                    {
                        "item": {
                            "id": "gid://shopify/InventoryItem/34431475449926"
                        },
                        "name": "on_hand",
                        "delta": 2,
                        "quantityAfterChange": null
                    }
                ]
            },
            "userErrors": []
        }
    },
    "extensions": {
        "cost": {
            "requestedQueryCost": 12,
            "actualQueryCost": 12,
            "throttleStatus": {
                "maximumAvailable": 2000.0,
                "currentlyAvailable": 1988,
                "restoreRate": 100.0
            }
        }
    }
}
1 Like

Hey @Chadillac :waving_hand: - this looks like expected behaviour from what I can tell. If the quantityAfterChange values are showing up as “null” immediately after you run the mutation, this matches what we mention here in our docs:

{
  "data": {
    "inventorySetQuantities": {
      "inventoryAdjustmentGroup": {
        "id": "gid://shopify/InventoryAdjustmentGroup/32766566924310",
        "changes": [
          {
            "name": "available",
            // The delta is 1 because there were previously 101 on-hand inventory units, and the request specified setting the on-hand inventory quantity to 102 units.
            "delta": 1,
            // This field always returns `null` immediately after running the mutation. The value of this field is available only after all written adjustments and moves have been processed.
            "quantityAfterChange": null
          }
        ],
        "reason": "Inventory correction",
        "referenceDocumentUri": "gid://shopify/Order/1974482927638"
      },
      "userErrors": []
    }

The process runs asyncronously, so the value for quantityAfterChange doesn’t populate until all the adjustments are complete. That said, I definitely understand that it’s not super easy to find that info without diving deep into the docs.

I’ll make a note to see if we can make this clearer - hope this helps a bit!

Thanks @Alan_G for pointing this out. That makes sense given the logic updates that may need to occur to calculate this.

Yes maybe add it to the GraphQL admin documentation as well to provide better visibility to this limitation.

1 Like