subgrounds.pagination.pagination module

This module contains the pagination algorithms (both regular and iterative) that make use of pagination strategies.

exception subgrounds.pagination.pagination.PaginationError(message, strategy)

Bases: RuntimeError

class subgrounds.pagination.pagination.PaginationStrategy(*args, **kwargs)

Bases: Protocol

step(page_data=None)

Returns the new query document and its variables which will be executed to get the next page of data. If this is the first query made as part of the pagination strategy, then page_data will be None.

If pagination should be interupted (e.g.: if enough entities have been queried), then this method should raise a StopPagination exception.

Parameters
  • page_data (Optional[dict[str, Any]], optional) -- The previous query's response data.

  • (i.e. (If this is the first query) -- the first page of data), then it will be None.

  • None. (Defaults to) --

Returns

A tuple (doc, vars) where doc is the query document that will be executed to fetch the next page of data and vars are the variables for that document.

Return type

Tuple[Document, dict[str, Any]]

subgrounds.pagination.pagination.paginate(schema, doc, pagination_strategy)

Executes the request document doc based on the GraphQL schema schema and returns the response as a JSON dictionary.

Parameters
  • schema (SchemaMeta) -- The GraphQL schema on which the request document is based

  • doc (Document) -- The request document

Returns

The response data as a JSON dictionary

Return type

dict[str, Any]

subgrounds.pagination.pagination.paginate_iter(schema, doc, pagination_strategy)

Executes the request document doc based on the GraphQL schema schema and returns the response as a JSON dictionary.

Parameters
  • schema (SchemaMeta) -- The GraphQL schema on which the request document is based

  • doc (Document) -- The request document

Returns

The response data as a JSON dictionary

Return type

dict[str, Any]