Hi Lucy,
Thanks for the follow-up! I see the date format is now correct, but you’re still experiencing the infinite pagination issue. This is actually a common problem with Shopify’s GraphQL orders query, and there are a few additional things we need to address:
## Issue #1: Missing sortKey Parameter
The most likely cause is that you’re missing a sortKey parameter. Without this, Shopify’s pagination can return inconsistent results and cause infinite loops.
Updated Query:
{
"query": "query {
orders(
first: 250,
query: \"created_at:>='2025-06-01T00:00:00Z' AND created_at:<='2025-06-02T00:00:00Z'\",
sortKey: CREATED_AT,
reverse: false
) {
edges {
node {
id
createdAt
// ... your other fields
}
cursor
}
pageInfo {
hasNextPage
endCursor
}
}
}"
}
## Issue #2: API Scope Limitations
By default, Shopify only allows access to the last 60 days of orders. If you’re querying for June 1st, 2025, and that’s beyond 60 days from today, you won’t get any results, but the API might still show hasNextPage: true.
Solution: Your app needs the read_all_orders scope to access historical orders beyond 60 days.
## Issue #3: Verify Your Date Range
Double-check that there are actually orders in your specified date range. You can test this by:
- First, check if orders exist in that range:
{
"query": "query {
orders(
first: 10,
query: \"created_at:>='2025-06-01T00:00:00Z' AND created_at:<='2025-06-02T00:00:00Z'\",
sortKey: CREATED_AT
) {
edges {
node {
id
createdAt
}
}
pageInfo {
hasNextPage
endCursor
}
}
}"
}
- If no results, try a broader range:
{
"query": "query {
orders(
first: 10,
sortKey: CREATED_AT,
reverse: true
) {
edges {
node {
id
createdAt
}
}
}
}"
}
## Issue #4: Pagination Logic Check
Make sure your pagination logic checks for hasNextPage before continuing:
// Pseudo-code for proper pagination
let hasNextPage = true;
let cursor = null;
let allOrders = [];
while (hasNextPage) {
const response = await makeGraphQLQuery(cursor);
const orders = response.data.orders;
// Add orders to your collection
allOrders.push(...orders.edges.map(edge => edge.node));
// Update pagination variables
hasNextPage = orders.pageInfo.hasNextPage;
cursor = orders.pageInfo.endCursor;
// Safety check - if you're getting the same cursor, break
if (previousCursor === cursor) {
console.log("Same cursor detected, breaking loop");
break;
}
previousCursor = cursor;
}
## Complete Working Example:
{
"query": "query($cursor: String) {
orders(
first: 250,
after: $cursor,
query: \"created_at:>='2025-06-01T00:00:00Z' AND created_at:<='2025-06-02T00:00:00Z'\",
sortKey: CREATED_AT,
reverse: false
) {
edges {
node {
id
createdAt
orderNumber
}
cursor
}
pageInfo {
hasNextPage
endCursor
}
}
}",
"variables": {
"cursor": null
}
}
The sortKey: CREATED_AT parameter should resolve the infinite pagination issue you’re experiencing. This ensures Shopify returns results in a consistent order, which is essential for proper cursor-based pagination.
Let me know if this resolves the issue or if you’re still seeing problems after adding the sortKey!
Best regards,
Shubham | Untechnickle