Bulk operation ignores `first` on orders

Solved
Highlighted
New Member
2 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!

1 Like
Highlighted
Shopify Expert
4124 29 383

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
Highlighted
New Member
2 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
Highlighted
Shopify Expert
4124 29 383

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