Skip to content

Hooks ​

The query hook that restricts or extends the statement behind a field.

QueryHook ​

source

python
QueryHook(load: Sequence[LoadType] = _UnsetLoad()) -> None

Loads 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 ​

python
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 ​

python
check_model(model: type[DeclarativeBase]) -> None

Checks that the top-level attributes of load can be loaded from model.

Raises:

TypeDescription
QueryHookErrorIf an attribute belongs neither to model nor to a model it inherits from.

column_load_options ​

python
column_load_options(alias: AliasedClass[Any]) -> list[_AbstractLoad]

Returns undefer options for the columns in load, read from alias.

info ​

python
info: Info[Any, Any]

Strawberry Info of the current request.

Raises:

TypeDescription
QueryHookErrorIf no request is being resolved.

info_var ​

python
info_var: ContextVar[Info[Any, Any] | None] = ContextVar('info', default=None)

Strawberry Info of the current request.

load ​

python
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 ​

python
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 ​

python
load_relationships(alias: AliasedClass[Any]) -> list[_AbstractLoad]

Returns the loader options of the relations in load, loaded from alias.