Hooks
The query hook that restricts or extends the statement behind a field.
QueryHook
QueryHook(load: Sequence[LoadType] = _UnsetLoad()) -> NoneLoads extra columns and relations, or edits the SELECT, for the type, field or repository it is attached to.
Override apply_hook to edit the statement; read the current request from info.
apply_hook
apply_hook(statement: SelectOf[DeclarativeT], alias: AliasedClass[DeclarativeT]) -> SelectOf[DeclarativeT]Returns statement edited, for instance with a filter or a join; unchanged by default.
alias is the alias of the model the hook runs on: the related model for a relation field.
check_model
check_model(model: type[DeclarativeBase]) -> NoneChecks that the top-level attributes of load can be loaded from model.
Raises:
| Type | Description |
|---|---|
QueryHookError | If an attribute belongs neither to model nor to a model it inherits from. |
column_load_options
column_load_options(alias: AliasedClass[Any]) -> list[_AbstractLoad]Returns undefer options for the columns in load, read from alias.
info
info: Info[Any, Any]Strawberry Info of the current request.
Raises:
| Type | Description |
|---|---|
QueryHookError | If no request is being resolved. |
info_var
info_var: ContextVar[Info[Any, Any] | None] = ContextVar('info', default=None)Strawberry Info of the current request.
load
load: Sequence[LoadType] = field(default_factory=_UnsetLoad)Columns and relations to load, a relation with its own list.
Example: [User.name, (User.addresses, [Address.street])]
load_columns
load_columns(statement: SelectOf[DeclarativeT], alias: AliasedClass[Any], mode: ColumnLoadingMode) -> tuple[SelectOf[DeclarativeT], list[_AbstractLoad]]Loads the columns in load, as undefer options or, in "add" mode, as selected columns.
load_relationships
load_relationships(alias: AliasedClass[Any]) -> list[_AbstractLoad]Returns the loader options of the relations in load, loaded from alias.