Bulk operation ignores `first` on orders

Solved
godzilla
New Member
3 0 1

Hi, we're trying to fetch a customer list with their first orders. While this query works as expected in its' non-bulk variant:

customer(id: "gid://shopify/Customer/1") {
    id
    firstName
lastName orders(first: 1) { edges { node { id } } } }

 

The equivalent bulk query ignores `first` and returns all of the orders for a particular customer, e.g. (ids are changed)

 

{"id":"gid:\/\/shopify\/Customer\/1","Jane":"Steven","lastName":"Doe"}
{"id":"gid:\/\/shopify\/Customer\/2","firstName":"John","lastName":"Doe"}
{"id":"gid:\/\/shopify\/Order\/55","__parentId":"gid:\/\/shopify\/Customer\/2"}
{"id":"gid:\/\/shopify\/Order\/56","__parentId":"gid:\/\/shopify\/Customer\/2"}
...

 

 

Here's the full bulk query we're using:

 

mutation {
    bulkOperationRunQuery(
        query:\"\"\" {
            customers {
                edges {
                    node {
                        id
                        firstName
                        lastName
                        orders(first: 1) {
                            edges {
                                node {
                                    id
                                }
                            }
                        }
                    }
                }
            }
        }
        \"\"\"
    ) {
        bulkOperation {
            id
            status
        }
        userErrors {
            field
            message
        }
    }
}

Example bulk operation id - 'gid://shopify/BulkOperation/24174395480'

 

Any ideas why that might be happening? Thank you!

HunkyBill
Shopify Expert
4472 45 484

This is an accepted solution.

If you read the Documentation of Bulk downloads, you can see the first parameter is mentioned as optional, and ignored if present.

The first argument is optional and ignored if present, so it can be removed.

So even if you include it, as first:1 for the customer orders, it'll be stripped and you'll get all the orders.

Looks like you may be better off just iterating customers and getting the first order.

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

Thank you! That clears it up.

I wish there was actual documentation for it though, not some bits of it hidden within the tutorial. "Optional, and ignored" is a very weird statement - it's simply "ignored

0 Likes
HunkyBill
Shopify Expert
4472 45 484

I guess the point of optional and ignored is to emphasize that your query will not error out if included (hence optional or, it can be there or not, makes no difference to the parser) and then yes, ignored. Writing documentation is tough!

The day someone wrote that up, I am sure they meant well, as they described the situation but made it a little odd to state the obvious?

 

Custom Shopify Apps built just for you! hunkybill@gmail.com http://www.resistorsoftware.com
0 Likes
Kris_Doyle
Shopify Partner
87 0 19

Would be nice if this was allowed in Bulk Operations.

There are many cases where I only need the "first" of a set of child nodes. For example, I might want all products, but only the first variant from each product. By forcing the query to return all child nodes, even when I only need the first, creates an operation that is orders of magnitude more cycles than it needs to be. In many cases (for us) this results in a query that takes an hour to run and does MUCH more work on the backend than is needed. This is a huge waste of Bulk Operation resources when the data returned is only going to be thrown out anyways.

Kind of defeats the whole purpose of GraphQL in this case...just sayin'

0 Likes
HunkyBill
Shopify Expert
4472 45 484

There is always just using GraphQL without the Bulk option too then. So you have to keep track of a cursor and make some extra API calls. I bet that is just as or even more even efficient than asking for bulk data, and then writing in the logic to ignore a lot of it. Just saying.

 

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