pub fn paginate_backward<T, F, Fut>(
fetch_page: F,
) -> impl Stream<Item = Result<T, Error>>Expand description
Creates a backward paginated stream from a fetch function.
Similar to paginate, but iterates backward through pages using
has_previous_page and start_cursor instead of has_next_page and end_cursor.
Note: Items within each page are yielded in the order returned by the server. The backward pagination only affects which pages are fetched, not item order within pages.
§Requirements
The fetch function must return a Page with has_previous_page and start_cursor
populated. The GraphQL query should:
- Use
lastandbeforeparameters (instead offirstandafterfor forward pagination) - Query
hasPreviousPageandstartCursorinpageInfo
§Page Size
The last parameter specifies how many items to fetch per page. If last exceeds the
server’s maximum page size, the request will fail. Query serviceConfig to discover
the page size limits:
query {
serviceConfig {
defaultPageSize(type: "Query", field: "objects")
maxPageSize(type: "Query", field: "objects")
}
}§Example
ⓘ
let stream = paginate_backward(move |cursor| {
let client = client.clone();
async move {
// Query with `last` and `before` parameters
// and fetch `hasPreviousPage` and `startCursor` in pageInfo
client.fetch_page_backward(cursor.as_deref()).await
}
});