GraphQL: query and pagination error

Lucho
Tourist
3 0 1

Hi people,

I am facing a problem with the queries and pagination:
example:

the query is:

orders( first: 250 query:"tag:'anytag'") 

and the result is:

{
  orders: {
    pageInfo: { hasNextPage: true, hasPreviousPage: false },
    edges: []
  }
}

As you can see, the result is empty, but "hasNextPage" is "true", the problem there is no a "offset" parameter, I can't get the next page

any idea?

 

thanks and regards

Replies 4 (4)
hassain
Shopify Staff (Retired)
Shopify Staff (Retired)
624 104 178

Hi @Lucho .

 

Would it be possible for you to share the value of the X-Request-ID response header from the Shopify API response for this GraphQL query? With this information we can go through our platform logs and see why this unexpected outcome occurred.  

Hassain | Developer Support Specialist @ Shopify
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Click Accept as Solution 

Lucho
Tourist
3 0 1

Hi, @hassain

thanks for your response

sure,

in this query:

{
  orders(first:250, sortKey: PROCESSED_AT, reverse:false, query:"tag:'packed'") {
} }

 

'x-request-id': '0368a949-6ccc-4e5d-ae8f-6c0c5d5e20a2'
I have no result:

{
  orders: {
    pageInfo: { hasNextPage: true, hasPreviousPage: false },
    edges: []
  }
}

but, if i simple set reverse:true 

{
  orders(first:250, sortKey: PROCESSED_AT, reverse:true, query:"tag:'packed'") {
  }
}

'x-request-id': 'f320c026-f329-44d0-b0ce-6b546dd7043d',
then, I got results:

{
  orders: {
    pageInfo: { hasNextPage: true, hasPreviousPage: false },
    edges: [
      [Object], [Object], [Object], [Object], [Object], [Object]
    ]
  }
}

 

hassain
Shopify Staff (Retired)
Shopify Staff (Retired)
624 104 178

Hi @Lucho ,

 

One important thing to keep in mind is that any app that is using the Orders resource of the Admin API is only allowed to access the last 60 days of orders by default. If they would like to access orders from earlier than the last 60 days, they need to first submit a request to Shopify and get approved for that. From our Orders REST API doc (https://shopify.dev/docs/admin-api/rest/reference/orders/order😞  

 

As of June 6th, 2018, only the last 60 days' worth of orders from a store will be accessible from the Order resource by default. If you want to access older orders, then you need to request access to all orders. If your app is granted access, then you can add the read_all_orders scope to your app along with read_orders or write_ordersPrivate apps are not affected by this change and are automatically granted the scope.

Now going back to your issue - with your first request you were trying to access the first 250 orders from the store that are filtered by a certain tag (tag=packed). No results were returned, as the first 250 orders that meet this criteria are all older than 60 days. However, when you reverse this query (as you did with the second request), you are pulling the most recent 250 orders which some fall within the 60 day timestamp so you do indeed see a results.

 

In order to fix this issue so you do not have to use reverse:true every time, you can specify an additional query parameter to only pull orders created after a certain date. This way you can specify to pull only orders created within the last 60 days, so your query will always get results. Here is an example:

 

{
  orders(first:20, query:"tag:'delivered' AND created_at:>'2020-03-01'") {
    pageInfo {
      hasNextPage
      hasPreviousPage
    }
    edges {
      cursor
      node {
        id 
        createdAt
      }
    }
 }
}

Alternatively, you could also reach out to Shopify to request access for read_all_orders and you would not have to worry about the 60 days limit.

Hassain | Developer Support Specialist @ Shopify
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Click Accept as Solution 

Lucho
Tourist
3 0 1

Hi @hassain,

Thanks for your response, but the case I post was only an example, I have a different issue in the real app, I need to execute something like this: 

orders(first:250, sortKey: PROCESSED_AT, reverse:false, query:"tag:NOT 'packed'") {
}

And sometimes the store has the last orders with the tag but old orders without the tag.

I've learn and used always the querys with the logic of first the query filters all the results and then the limit is applied, but reading your explanation the query is working in other way, in opposite logic. Is it correct? Am I understanding correctly?
And the other issue with filter by date, I can't use your suggestion because we never know how many orders there are every day.

thanks and regards