GraphQL equivalent for variant.inventory_management == "shopify"

The REST documentation says that the GraphQL equivalent of variant.inventory_management is inventoryLevels, but it’s not clear how.

With REST, I currently do this check: variant.inventory_management == "shopify", which means the inventory is tracked and is managed by Shopify.

What is the equivalent in GraphQL? I’m assuming it involves 2 checks:

  1. Assert productVariantinventoryIteminventoryLevels(first: 1)locationisFulfillmentService == false
  2. Assert productVariantinventoryItemtracked == true

Is that enough to assert that the inventory is tracked and is managed by Shopify?

You can use the managed_by query param on the product variants graphql :smiley:

@flavio-b, yes. It’s enough.

REST:

variant.inventory_management == "shopify"

GraphQL:

productVariant {
  inventoryItem {
    tracked
  }
}

productVariant.inventoryItem.tracked == true

Thanks! That’s interesting. It could work in my case, but I’m curious:

How does it arrive at the managed_by value using the underlying data?

I need to know so I can perform my own check based on fields I might have on hand, as it’s not ideal to issue another fetch over the network just to get Shopify to apply a filter for me.

Also, the filter name seems a bit inconsistent. For example:

  1. What’s the difference between managed and tracked?
  2. If managed_by is supposed to be a fulfillment service handle, where does it get the "shopify" value from? When I try to read the fulfilment service handle from my items that are managed by Shopify, the fulfillment service is null, so there’s not even a handle, let alone one called "shopify".

Thank you for your input! However, what if the item is associated with a third-party fulfillment service? Would that automatically mean tracked == false?

The tracked field definition just says “Tracked: Whether inventory levels are tracked for the item.”

I suppose any fulfillment service does track inventory levels, so perhaps tracked is always true, even if the fulfilment service is not Shopify’s.

I’m sorry, I don’t know a way to set up a bogus 3P fulfillment service in my dev account so don’t have a way to test these assumptions, and the field definitions are not super clear.

I think the REST doc is outdated, I was wondering the same thing.

It seems even with the current REST API version, it’s only either “shopify” or “null” which basically maps to InventoryItem.tracked boolean (i.e. it will still display “shopify” even if the inventory is managed by a custom fulfillment service).

More info here: Replacement for variant inventory_management field?

@Jonathan-HA I see! But since GraphQL doesn’t have the “inventory_management” field on the variant, I’m wondering what’s the correct way to determine that an item is tracked and managed by Shopify.

My assumption is to dig into the location of the first inventoryLevel and check whether that location is a 3P fulfillment service, and also to check the tracked boolean on the inventoryItem. That’s awkward but it seems more precise, I just don’t know if it’s the “canonical” way.

Or, one could use the “managed_by” query filter, but that means you’d have to re-fetch variants to have Shopify apply a filter for you. I want to be able to pull a few dozen variants (and appropriate associations), and determine the “fulfiller” based on the data alone, without a query filter.

Its the same logic as inventory_management that you were using before.
Given the different APIs are surfacing the same data just in different ways.

As per the docs managed_by is a Filter by the fulfillment service that tracks the number of items in stock for the product variant.

This can also be found on as you suggested on productVariant > inventoryItem > inventoryLevel > location > fulfillment service if you need to store this information.
You also have it on the product/update webhook, in the old format if you are storing a copy of this data.