xm cloud – Graphql query for sitecore search iterating limited results

Yes, GraphQL search queries in Sitecore are inherently limited and must be paginated. You cannot fetch all documents in a single request without paging through them.

Sitecore’s GraphQL API follows standard cursor-based pagination, meaning:

You specify a limit (via first) to control how many results are returned.

You cannot request arbitrarily large result sets in one call.

To fetch the next batch of results, you must use the after cursor returned in the previous page.

This pattern is not specific to Sitecore it’s defined by the GraphQL pagination specification and implemented in Sitecore’s GraphQL schema.

Cursor-based pagination
Sitecore’s GraphQL documentation explicitly describes cursor pagination — using first, pageInfo, endCursor and hasNext:
doc.sitecore.com/ch/en/developers/cloud-dev/graphql-queries.html#cursor-based-pagination

Your query:

query {
  search(
    where: {
      AND: [
        { name: "_path", value: "{rootId}", operator: CONTAINS }
        { name: "_language", value: "{language}", operator: EQ }
      ]
    }
    first: 100
  ) {
    results { id }
    pageInfo { hasNext endCursor }
  }
}

Will return up to 100 results per call
Will include pageInfo with endCursor to fetch more

But it will never give you every document in one request if there are more than 100 results.

To iterate over all results, you must loop:

query FetchMore($after: String) {
  search(... first: 100, after: $after) {
    results { id }
    pageInfo { hasNext endCursor }
  }
}

until hasNext is false.

This is standard cursor pagination.

Read more here: Source link