Similar GraphQL queries giving different results

samarpan1738
New Member
3 0 0

Query 1 : 

 

 

mutation {
    bulkOperationRunQuery(
        query:"""
            {
            locations(query: "isActive:true"){
                edges{
                    node{
                        id
                        inventoryLevels{
                            edges{
                                node{
                                    id
                                    available
                                    incoming
                                    item{
                                        countryCodeOfOrigin
                                        id
                                        legacyResourceId
                                        sku
                                        variant{
                                            displayName
                                            id
                                            legacyResourceId
                                            product{
                                                id
                                                legacyResourceId
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        """
    ) {
      bulkOperation {
        id
        status
      }
      userErrors {
        field
        message
      }
    }
}

 

 

 

Response 1 : 

 

Query 2

 

 

mutation {
    bulkOperationRunQuery(
        query:"""
           {
                inventoryItems
                {
                    edges
                    {
                    node
                    {
                        id
                        inventoryLevels
                        {
                        edges
                        {
                            node{
                                id
                            location
                            {
                                id
                            }
                            available
                            id
                            item
                            {
                                id
                                variant
                                {
                                id
                                product
                                {
                                    id
                                }
                                }
                            }
                            }
                        }
                        }
                        locationsCount
                        
                    }
                    }
                }
            }
        """
    ) {
      bulkOperation {
        id
        status
      }
      userErrors {
        field
        message
      }
    }
}

 

 

 

Response 2 : 

 
 
Why are these 2 queries giving different results?? 
Query 1 gives only 16 items and Query 2 gives approx. 3000 items
0 Likes
Mircea_Piturca
Shopify Partner
1489 42 316

The first query returns only active locations, see isActive:true.

This is why it will return fewer results. I haven't run those queries, just a guess...

Finally—Add variant descriptions to your products
samarpan1738
New Member
3 0 0

Getting the same issue without the isActive filter too.

0 Likes
HunkyBill
Shopify Expert
4509 46 492

I dunno. It is kinda interesting. In the first query, you start off with locations and then immediately just dive into inventory levels. So great. An inventory level applies to an item at a location. You get 16 results.

In query 2 however, forgetting locations, we just say gimme Items! MMMnomnomnom Items... and from there ask for levels, at locations. And you get a lot more results.

So what are you really surprised about here? It is kinda interesting sure, but there is no root or firm footing to just what you are trying to accomplish. So just glossing over it, it seems like yes, you probably should be getting wildly different results.

Custom Shopify Apps built just for you! hunkybill@gmail.com http://www.resistorsoftware.com
0 Likes
samarpan1738
New Member
3 0 0

https://shopify.dev/docs/admin-api/rest/reference/inventory/inventorylevel#index-2021-04https://shopify.dev/docs/admin-api/rest/reference/inventory/inventorylevel#index-2021-04

 

Query 1 follows this path:- locations -> Inventory Levels-> Inventory Item -> Variant -> Product (For all locations give the inventory levels, For an inventory level give the associated inventory item)
I'm using locations to get to the inventory Levels because there is no direct way to get all inventory levels(i.e there is not inventoryLevels connection)

Query 2 follows the other way round :- inventory Items -> Inventory Levels  -> Variant -> Product (Give all the inventory Items, For an inventory item give all the inventory levels stocked at various locations)

They should give same results.

0 Likes