How to implement pagination with GraphQL for stack runs
Last updated: September 16, 2025
When querying stack runs using GraphQL, you may encounter a limit where only 50 runs are returned even if your stack has more runs. This is due to pagination limits in the API.
Using the ListRuns Query for Pagination
To retrieve all runs for a stack, use the dedicated ListRuns query instead of the basic stacks query. This query supports pagination through the before parameter.
Here's the complete query structure:
query ListRuns($stackId: ID!, $before: ID, $hasIgnoredRunsAccess: Boolean!) {
stack(id: $stackId) {
id
runs(before: $before) {
id
commit {
authorLogin
authorName
hash
timestamp
url
__typename
}
createdAt
finished
state
title
triggeredBy
updatedAt
__typename
}
__typename
}
}Implementing Pagination Loop
To retrieve all runs, you'll need to implement a pagination loop that fetches 50 runs at a time:
Initial Request: Start with your first query using these variables:
{ "stackId": "your-stack-id", "hasIgnoredRunsAccess": true }Subsequent Requests: After receiving the first batch of runs, use the ID of the oldest run from the response as the
beforeparameter for the next request:{ "stackId": "your-stack-id", "before": "oldest-run-id-from-previous-response", "hasIgnoredRunsAccess": true }Continue Loop: Repeat this process, always using the oldest run ID from each response as the
beforeparameter for the next request, until no more runs are returned.
Key Points
The API returns a maximum of 50 runs per request
Use the
beforeparameter with the oldest run ID to fetch the next batchContinue looping until the response contains fewer than 50 runs or is empty
This approach works for any stack regardless of the total number of runs