Need to retrieve more than a single page of Shopify store data? Shopify GraphQL API pagination makes it easy to work through large result sets without requesting everything at once. Using cursors, you can move through products, orders, customers, and other records in manageable batches.
In this guide, we’ll explain how Shopify GraphQL API pagination works, including how to use connections, edges, and page information to fetch the next set of results. Once you understand the basics, you can build reliable queries that get the data you need efficiently.
Shopify GraphQL API pagination: How Cursors and Connections Work
When a store has thousands of records, the key is not just retrieving them—it’s knowing exactly where to resume after each request. Shopify’s connection structure provides that roadmap, letting you fetch a manageable batch and continue without skipping ahead blindly.
First, let’s look at the pieces Shopify returns and how they work together. Understanding their roles makes it easier to build a query that can move through results reliably.
Understand connections, edges, and pageInfo
A connection is the paginated collection attached to a field, such as products or orders. Its edges contain individual results: each edge pairs a record in node with a cursor that marks its position in the result set.
The connection’s pageInfo tells you whether another page exists and provides cursor details. For example, hasNextPage indicates whether more results follow, while endCursor identifies the last edge in the current batch. A query might request these fields:
edges { cursor node { id } }to retrieve records and their cursors.pageInfo { hasNextPage endCursor }to determine whether and where to continue.
You can also request nodes directly when you only need the records, but edges are useful when you need each item’s cursor. Shopify’s GraphQL pagination documentation describes the connection pattern and its page information fields.
With those fields in place, the next step is choosing a direction and passing the cursor between requests. This determines how your query advances through the connection.
Choose first or last and follow the cursors
Use first to request items from the beginning of a connection, then pass the previous response’s endCursor as after to fetch the next batch. For example, products(first: 50, after: $cursor) continues after the cursor supplied in the variable.
For backward traversal, use last with before, typically following startCursor from the current page. Choose one direction for a given request, and check the matching flag—hasNextPage or hasPreviousPage—before making another call. This avoids unnecessary requests at the end of the connection.
Once your cursor flow is clear, set a page size that balances request count with the amount of data each response must process.
Set page sizes that fit your query
A larger page means fewer round trips, but it can also make responses heavier, especially when each product includes nested variants or inventory details. Shopify connections generally allow up to 250 items per page; choose a smaller value when records are complex or your application needs to stay responsive.
Consider starting with a moderate batch and adjusting based on response size and processing time. If you need to extract a very large dataset, Shopify’s bulk operations may be a better fit than repeatedly paging through a standard query.
Fetch More Results with Shopify GraphQL API Pagination
A cursor is useful only when your application carries it from one request to the next. Once that handoff is in place, you can turn a single query into a dependable process for collecting a complete dataset.
Start by connecting the cursor from one response to the next request. The query below shows how to pass it as a variable rather than inserting a cursor directly into the query text.
Build a query with after and endCursor
Declare a nullable String variable for the cursor. On the first request, leave it unset; for each later request, provide the preceding page’s endCursor.
query GetProducts($cursor: String) {
products(first: 50, after: $cursor) {
edges {
node { id title }
}
pageInfo {
hasNextPage
endCursor
}
}
}Keep the returned cursor exactly as Shopify provides it. Treat it as an opaque value: your application should pass it back unchanged, not parse it or try to calculate the next position. You can also request only the fields your task needs, keeping each response lighter.
With the query ready, the application can repeat the same request and update its cursor after every successful page.
Loop through pages until hasNextPage is false
Store each page’s records, then check hasNextPage. If it is true, set the next request’s cursor to endCursor; if it is false, stop. This condition prevents an unnecessary request after the final batch.
A practical loop should also account for failures: save progress after processing each page, and resume from the last successfully handled cursor if the run is interrupted. For example, an export job might write each batch to storage before requesting another. That approach limits lost work and helps prevent duplicate processing if a request must be retried.
Even a well-formed loop may need to pause when Shopify signals that query capacity is running low.
Handle rate limits and partial results
The Admin API uses query cost-based throttling. Check the response’s extensions.cost.throttleStatus fields, including available capacity and restore rate, and slow down when needed. Shopify’s API limits documentation explains how GraphQL query costs and throttling work.
Also inspect both data and errors: a response can contain usable partial data alongside GraphQL errors. Decide whether to save that page, retry it, or stop for review, rather than assuming an HTTP success means every field was returned. Use a measured backoff for throttled requests, and retry from the last confirmed cursor so the collection process remains consistent.
Make Pagination Reliable in Your Shopify App
A cursor loop can work perfectly in a quiet test store and still behave differently during a busy catalog update. A few safeguards help keep your results complete and your app steady when records change, requests fail, or response sizes grow.
First, consider what happens when the collection you are reading is changing while your job runs. The following practices help reduce gaps and duplicate processing.
Avoid duplicates and missed records as data changes
Pagination is not necessarily a frozen snapshot of a collection. If products are added, removed, or reordered between requests, later pages may not reflect exactly the same result set as earlier ones. Where supported, use a consistent sort order and a stable sort key, such as an ID or updated timestamp, rather than relying on an order that can shift during the run.
Make processing idempotent: saving the same record twice should not create a duplicate or corrupt the result. For example, upsert products by their Shopify ID, and record the last successful checkpoint. For ongoing syncs, combine a saved checkpoint with a small overlap window, then deduplicate by ID; this can catch updates that occur near a run’s boundary.
For high-change datasets, periodically reconcile your local records against Shopify instead of assuming one pass catches every change. The right approach depends on whether you are building a one-time export or a recurring sync.
Changing data is only one source of trouble. A robust implementation should also be tested against unusual responses and interrupted runs.
Test edge cases and recover from errors
Go beyond the happy path by testing an empty connection, a final page smaller than the requested batch, and a record updated while pagination is underway. Confirm that the app stops when there are no more pages and that a restart can continue from a valid checkpoint without duplicating completed work.
Also test throttling, timeouts, malformed responses, and GraphQL errors returned alongside partial data. Define whether each case should be retried, saved for review, or treated as a failed page. Keep retries bounded, and resume from the last confirmed checkpoint rather than advancing past data that was not successfully processed.
Once recovery behavior is dependable, reduce unnecessary work in each request to keep the job efficient.
Improve performance with selective fields and sensible batch sizes
Request only the fields your task uses. An export that needs product IDs and titles does not need deeply nested variant or inventory data; trimming selections can reduce response size and processing overhead. Shopify’s GraphQL pagination guidance explains the connection fields used to navigate results.
Choose a batch size that fits the complexity of those fields, then monitor response time, memory use, and query-cost data as the app runs. A smaller batch may be more reliable for large nested records, while a lean query can often handle larger batches. Measure and adjust rather than assuming the maximum page size is always fastest.
Turn Shopify Pagination into a Reliable Data Workflow
Shopify GraphQL API pagination gives you a practical way to retrieve large datasets in manageable steps. By following cursors through connections and using page information to guide each request, your app can collect records efficiently without trying to load everything at once.
For dependable results, pair that pagination flow with thoughtful query sizes, selective fields, and clear recovery strategies. Account for rate limits and changing data, and make processing safe to resume or repeat. With these habits in place, you can build Shopify data workflows that are both efficient and resilient—and get the information your app needs with confidence.