504 Gateway Time-out at Pagination (Orders)

Hey!

We are paginating through the Orders with the GraphQL API, and lots of our requests end up in 504 Gateway Time-out errors. We queried many fields on the Order object, some sub pages (like attachment), etc. But when we saw these timeouts, after a lots of trial and error, we reduced the query to the smallest we could. So we ended up a with query like this. But this query still results a 504 Gateway Time-out most of the times.

query Orders(
    $updatedFrom: ISODateTime
    $first: Int
) {
    orders(updated_from: $updatedFrom) {
        data(first: $first) {
            edges {
                node {
                    ...OrderFragment
                }
            }
            pageInfo {
                hasNextPage
                endCursor
            }
        }
    }
}

fragment OrderFragment on Order {
    id
}

Variables:

{
    "updatedFrom": "2025-08-29T12:44:06.000Z",
    "first": 1
}

Now I am out of ideas what could I try to get a reliable response.

We must use the updated_from, because we don’t want to query all the orders. But I also tried without this filter, and that also timed out. We cannot reduce the page count (first) under 1. We also tried with Exponential Backoff (wait 1-5-10+ mins and retry) logic, but that didn’t help either.

Do you have any recommendations? Thanks in advance!

Hi David,

For this query, please include an updated_to and paginate in smaller time windows. Even with first: 1, the API still needs to find and sort across every order updated since updated_from. In your example, updated_from is 2025-08-29T12:44:06.000Z, so that can still be a very large scan.

I’d recommend polling bounded windows, for example:

orders(updated_from: “2025-08-29T12:44:06.000Z”, updated_to: “2025-08-30T12:44:06.000Z”) {
data(first: 50) { … }
}

If a small window with only id still returns 504, please share a request_id. Also there is a account id field in your Profile section here in the forum you can complete. That will help agents to give you a more accurate response.

Perfect, thank you very much for the suggestion. I will give it a try.