What replaces since_id filtering with GraphQL - Orders

Highlighted
Shopify Expert
3986 18 341

I am used to setting up a filter that returns all orders since since_id in the RestAPI. Now that I am hammering orders using the GraphQL ID I don't see that as an option. How does one segment the same way? What is the sauce for that? Does anyone have a pseudo-code example?

 

 

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

C'mon. someone must know this. Seems like it is a silly exercise to pin the algorithm to getting An Order, and then using that to then page through all the newer orders using something like createdAt > the first order.

 

Really? That is messy. No such thing as just saying hey, Shopify, send me all orders since I last grabbed a bunch, and oh hey, the ID of the last one I grabbed was blah?

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

This code totally fails me. I want orders from the past few days... instead I get a ton from as far back as November. Not terribly useful. What am I doing wrong?

 

  mutation {
    bulkOperationRunQuery(
      query:"""
      {
        orders(query: "createdAt:>2020-01-24T15:59:28Z") {
          edges {
            node {
              id
              name
              lineItems {
                edges {
                  node {
                    sku
                    quantity    
                  }
                }
              }
            }
          }
        }
      }    
      """
    ) 
    {
        bulkOperation {
          id
          status
        }
        userErrors {
          field
          message
        }
      }
    }  
Custom Shopify Apps built just for you! hunkybill@gmail.com http://www.resistorsoftware.com
0 Likes
Shopify Expert
3986 18 341

I changed the query to be

 

 orders(query: "created_at:>2020-01-24T15:59:28Z") {

Which was the time stamp for an order with a created at date of

 

"2020-01-24T10:59:28-05:00"

So now my bulk request comes back with results from many hours earlier. The order I want as the since_id is time stamped "2020-01-24T10:59:28-05:00"

 

But I actually got back an order from

 

	"2020-01-24T00:05:51-05:00"

So what is the deal? There is very little in the documentation about temporal queries. And we've been asking about this actively since December 2019. Can we get some traction on how to deal with this?

  • created_at_min
  • created_at_max
  • since_id

... were pretty useful concepts with RestAPI that are not apparently so easy with GraphQL. So where are the smarty pants to help out here? What is the good syntax? And also, note how I got burned by the GraphQL syntax of createAt which was apparently in a query supposed to be created_at? How are supposed to deal with that? Is GraphQL actually a nightmare of camel-case, snake-case, stoner-case?

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

This sucks. There is no seemingly accurate way of using GraphQL to scan a subset of orders and get the exact ones you need. How are we supposed to segment orders in Shopify for processing? If I cannot say hey, give me all the orders I have not yet processed, it is chaos. Why is this so difficult? I am reverting to RestAPI in disgust until someone shows me the light of how simple and elegant it is with GraphQL.

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

Hey Bill, playing around in my GraphQL sandbox against my Shopify dev store, I can seem to query against IDs pretty reliably:

{
  orders(first: 5, query:"id:>969451308043") {
    edges {
	node {
	    id,
            createdAt
         }
     }
  }
}

Since you're looking for a since_id equivalent anyway, maybe try your mutation tests with the ID query instead of the timestamp query?

0 Likes
Highlighted
Shopify Expert
3986 18 341

damn that. ID in my head is usually the GID and not the old school restful one. So I never tried a bulk export with that. Will do and report back. Might do the trick.

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

Yeah it's weird, I started out trying with the GID form and when that didn't work just tried the numeric form. A little odd how it's switched up like that because in every other place the GID form is treated as the canonical ID. Anyway, let us know if it solves your issue!

0 Likes
Highlighted
Shopify Expert
3986 18 341

Nope. Damn...

 

So what I got back was close but no cigar. I received orders created before the id I presented in my query. Not off by much but still, not an accurate set of orders. So back to the drawing board!!

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

What is shocking (not really but) is the fact that an order placed BEFORE one in my returned result set, ie) Friday morning at 5:00 am when my query order was created Friday at 11:00a, well, it has a higher ID number. So it was returned in the set, as it qualified.

 

So that means the assignment of an ID to an order can be out of whack with the temporal nature of its existence. Wrap your heads around that and feast.

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