subgrounds.pagination package#
Submodules#
- subgrounds.pagination.pagination module
- subgrounds.pagination.preprocess module
PaginationNode
PaginationNode.node_idx
PaginationNode.filter_field
PaginationNode.first_value
PaginationNode.skip_value
PaginationNode.filter_value
PaginationNode.filter_value_type
PaginationNode.key_path
PaginationNode.inner
PaginationNode.node_idx
PaginationNode.filter_field
PaginationNode.first_value
PaginationNode.skip_value
PaginationNode.filter_value
PaginationNode.filter_value_type
PaginationNode.key_path
PaginationNode.inner
PaginationNode.get_vardefs()
is_pagination_node()
get_orderBy_value()
get_orderDirection_value()
get_filtering_args()
get_filtering_value()
generate_pagination_nodes()
normalize()
prune_doc()
- subgrounds.pagination.strategies module
StopPagination
SkipPagination
LegacyStrategyArgGenerator
LegacyStrategyArgGenerator.active_idx
LegacyStrategyArgGenerator.Cursor
LegacyStrategyArgGenerator.Cursor.inner_idx
LegacyStrategyArgGenerator.Cursor.filter_value
LegacyStrategyArgGenerator.Cursor.queried_entities
LegacyStrategyArgGenerator.Cursor.stop
LegacyStrategyArgGenerator.Cursor.page_count
LegacyStrategyArgGenerator.Cursor.keys
LegacyStrategyArgGenerator.Cursor.page_node
LegacyStrategyArgGenerator.Cursor.inner
LegacyStrategyArgGenerator.Cursor.is_leaf
LegacyStrategyArgGenerator.Cursor.update()
LegacyStrategyArgGenerator.Cursor.step()
LegacyStrategyArgGenerator.Cursor.first_arg_value()
LegacyStrategyArgGenerator.Cursor.args()
LegacyStrategyArgGenerator.Cursor.reset()
LegacyStrategyArgGenerator.cursor
LegacyStrategyArgGenerator.step()
LegacyStrategy
ShallowStrategyArgGenerator
ShallowStrategyArgGenerator.Cursor
ShallowStrategyArgGenerator.Cursor.page_node
ShallowStrategyArgGenerator.Cursor.inner
ShallowStrategyArgGenerator.Cursor.inner_idx
ShallowStrategyArgGenerator.Cursor.filter_value
ShallowStrategyArgGenerator.Cursor.queried_entities
ShallowStrategyArgGenerator.Cursor.stop
ShallowStrategyArgGenerator.Cursor.page_count
ShallowStrategyArgGenerator.Cursor.keys
ShallowStrategyArgGenerator.Cursor.page_node
ShallowStrategyArgGenerator.Cursor.inner
ShallowStrategyArgGenerator.Cursor.inner_idx
ShallowStrategyArgGenerator.Cursor.filter_value
ShallowStrategyArgGenerator.Cursor.queried_entities
ShallowStrategyArgGenerator.Cursor.page_count
ShallowStrategyArgGenerator.Cursor.from_pagination_node()
ShallowStrategyArgGenerator.Cursor.is_leaf
ShallowStrategyArgGenerator.Cursor.active_cursor
ShallowStrategyArgGenerator.Cursor.iter()
ShallowStrategyArgGenerator.Cursor.mapi()
ShallowStrategyArgGenerator.cursor
ShallowStrategyArgGenerator.iter_cursors()
ShallowStrategyArgGenerator.update_cursor()
ShallowStrategyArgGenerator.step()
ShallowStrategy
- subgrounds.pagination.utils module
Module contents#
This module contains all code related to automatic pagination.
The pagination
module contains the pagination algorithms (both regular and iterative)
that make use of PaginationStrategies
.
The preprocess
and strategties
modules implement the currently supported PaginationStrategies
:
LegacyStrategy
and ShallowStrategy
.
The utils
module contains some generic functions that are useful in the context of pagination.
- subgrounds.pagination.generate_pagination_nodes(schema, document)#
- class subgrounds.pagination.LegacyStrategy(schema, document)#
Bases:
object
- schema: SchemaMeta#
- arg_generator: LegacyStrategyArgGenerator#
- step(page_data=None)#
- subgrounds.pagination.normalize(schema, document, pagination_nodes)#
Inject various graphql components to "normalize" the query for pagination.
When we paginate a query, we inject custom filtering based on the order by values. We also add GraphQL variables so that PaginationStrategy only need to change those
to perform pagination.
- The main process for normalization begins by recursively adjusting Selection nodes
within the Query tree. We only apply the following steps if the node needs to be paginated.
- > Note, these steps always check the current selection and will merge new values
and selections onto whats currently there.
Ensure id is on the Selection
Replace first argument value by $firstX
Replace skip argument value by $skipX
With the orderBy (default being id), generate where filtering arguments
These are used to filter out values when paginating
Set where filtering values (deep union / merge)
- subgrounds.pagination.paginate_iter(schema, doc, pagination_strategy, headers)#
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:
- subgrounds.pagination.paginate(schema, doc, pagination_strategy, headers)#
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:
- exception subgrounds.pagination.PaginationError(message, strategy)#
Bases:
RuntimeError
- class subgrounds.pagination.PaginationNode(node_idx, filter_field, first_value, skip_value, filter_value, filter_value_type, key_path, inner=<factory>)#
Bases:
object
Class representing the pagination config for a single GraphQL list field.
- filter_field#
Name of the node's filter field, e.g.: if
filter_name
istimestamp_gt
, thenfilter_field
istimestamp
- Type:
- filter_value#
Initial value of the filter argument (i.e.:
where: {filter: FILTER_VALUE}
)- Type:
Any
- key_path#
Location in the list field to which this pagination node refers to in the initial query
- inner#
Nested pagination nodes (if any).
- Type:
- get_vardefs()#
Returns a list of variable definitions corresponding to this pagination node's pagination arguments as well as the variable definitions related to any nested pagination nodes.
- Parameters:
self (PaginationNode) -- The current PaginationNode
- Returns:
_description_
- Return type:
- class subgrounds.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 beNone
.If pagination should be interupted (e.g.: if enough entities have been queried), then this method should raise a
StopPagination
exception.- Parameters:
- 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:
- subgrounds.pagination.prune_doc(document, args)#
- class subgrounds.pagination.ShallowStrategy(schema, document)#
Bases:
object
- schema: SchemaMeta#
- arg_generator: ShallowStrategyArgGenerator#
- step(page_data=None)#