Skip to content

Configuration options ​

The mapper-wide configuration, and the configuration behind each generated type.

StrawchemyConfig ​

source

python
StrawchemyConfig(dialect: SupportedDialect, session_getter: AnySessionGetter = default_session_getter, auto_snake_case: bool = True, repository_type: AnyRepositoryType = StrawchemySyncRepository, filter_overrides: FilterMap | None = None, execution_options: dict[str, Any] | None = None, default_id_field_name: str = 'id', deterministic_ordering: bool = True, strict: bool = True, auto_is_type_of: bool = True, include: FieldSpec = 'all', exclude: FieldSpec | None = None, pagination: FieldSpec | None = None, order_by: FieldSpec | None = None, distinct_on: FieldSpec | None = None, pagination_default_limit: int = 100, pagination_default_offset: int = 0) -> None

Global configuration for Strawchemy.

auto_is_type_of ​

python
auto_is_type_of: bool = True

Auto-generate is_type_of (an isinstance check against the model) on mapped output object types so they work as GraphQL Union / interface members without boilerplate. A user-defined is_type_of on the decorated class is always respected. Set to False to disable globally.

auto_snake_case ​

python
auto_snake_case: bool = True

Automatically convert snake cased names to camel case

default_id_field_name ​

python
default_id_field_name: str = 'id'

Name for primary key fields arguments on primary key resolvers.

deterministic_ordering ​

python
deterministic_ordering: bool = True

Force deterministic ordering for list resolvers.

dialect ​

python
dialect: SupportedDialect

distinct_on ​

python
distinct_on: FieldSpec | None = None

Enable/disable distinct on on list resolvers.

distinct_on_config ​

python
distinct_on_config: DTOConfig

exclude ​

python
exclude: FieldSpec | None = None

Globally excluded fields.

execution_options ​

python
execution_options: dict[str, Any] | None = None

SQLAlchemy execution options for strawberry operations.

field_config ​

python
field_config: DTOConfig

filter_overrides ​

python
filter_overrides: FilterMap | None = None

Override default filters with custom filters.

include ​

python
include: FieldSpec = 'all'

Globally included fields.

inspector ​

python
inspector: SQLAlchemyGraphQLInspector = field(init=False)

order_by ​

python
order_by: FieldSpec | None = None

Enable/disable order by on list resolvers.

order_config ​

python
order_config: DTOConfig

pagination ​

python
pagination: FieldSpec | None = None

Enable/disable pagination on list resolvers.

pagination_config ​

python
pagination_config: DTOConfig

pagination_default_limit ​

python
pagination_default_limit: int = 100

Default pagination limit when pagination=True.

pagination_default_offset ​

python
pagination_default_offset: int = 0

Default pagination offset when pagination=True.

repository_type ​

python
repository_type: AnyRepositoryType = StrawchemySyncRepository

Repository class to use for auto resolvers.

session_getter ​

python
session_getter: AnySessionGetter = default_session_getter

Function to retrieve SQLAlchemy session from strawberry Info object.

strict ​

python
strict: bool = True

When False, silently skip (and warn about) model columns whose type hint has no GraphQL mapping, instead of failing the schema build. Explicit type_overrides are always honored. Note: types mapped only via strawberry.Schema(scalar_overrides=...) are not visible here; force them with type_overrides= instead.

DTOConfig ​

source

python
DTOConfig(purpose: Purpose, include: FieldSpec | None = None, exclude: FieldSpec | None = None, global_include: FieldSpec | None = None, global_exclude: FieldSpec | None = None, partial: bool | None = None, partial_default: Any = None, unset_sentinel: Any = DTOUnset, type_overrides: Mapping[Any, Any] = dict(), annotation_overrides: dict[str, Any] = dict(), aliases: Mapping[str, str] = dict(), exclude_defaults: bool = False, alias_generator: Callable[[str], str] | None = None, scope: DTOScope | None = None, exclude_from_scope: bool = False, tags: set[str] = set()) -> None

Control the generated DTO.

Raises:

TypeDescription
ValueErrorIf both aliases and alias_generator are provided.

alias ​

python
alias(name: str) -> str | None

alias_generator ​

python
alias_generator: Callable[[str], str] | None = None

Builds each field's alias from its name. Mutually exclusive with aliases.

aliases ​

python
aliases: Mapping[str, str] = field(default_factory=dict)

Source field name to its name on the generated DTO. Mutually exclusive with alias_generator.

annotation_overrides ​

python
annotation_overrides: dict[str, Any] = field(default_factory=dict)

Replacement annotations, keyed by field name.

copy_with ​

python
copy_with(purpose: Purpose | type[DTOUnset] = DTOUnset, *, include: FieldSpec | None = None, global_include: FieldSpec | None = None, exclude: FieldSpec | None = None, global_exclude: FieldSpec | None = None, partial: bool | type[DTOUnset] | None = DTOUnset, unset_sentinel: Any | type[DTOUnset] = DTOUnset, type_overrides: Mapping[Any, Any] | type[DTOUnset] = DTOUnset, annotation_overrides: dict[str, Any] | type[DTOUnset] = DTOUnset, aliases: Mapping[str, str] | type[DTOUnset] = DTOUnset, exclude_defaults: bool | type[DTOUnset] = DTOUnset, alias_generator: Callable[[str], str] | type[DTOUnset] = DTOUnset, partial_default: Any | type[DTOUnset] = DTOUnset, scope: DTOScope | type[DTOUnset] | None = DTOUnset, exclude_from_scope: bool | type[DTOUnset] = DTOUnset, tags: set[str] | type[DTOUnset] = DTOUnset) -> DTOConfig

Create a copy of the DTOConfig with the specified changes.

exclude ​

python
exclude: FieldSpec | None = None

Explicitly exclude fields from the generated DTO. Implies everything else is included.

exclude_defaults ​

python
exclude_defaults: bool = False

exclude_from_scope ​

python
exclude_from_scope: bool = False

excluded_fields ​

python
excluded_fields: FieldSet = field(init=False)

from_include ​

python
from_include(include: FieldSpec | Literal[False] | None = None, purpose: Purpose = Purpose.READ) -> Self

Create a DTOConfig from an include specification.

Factory method for creating a DTOConfig with a simplified interface, converting an IncludeFields specification into a complete configuration object. This is useful for building configs when only the include/exclude specification matters.

Parameters:

NameTypeDescriptionDefault
includeFieldSpec | Literal[False] | NoneThe field inclusion specification. Can be: - None: Include no fields (converted to empty set) - "all": Include all fields - list or set of field names: Include only these specific fields Defaults to None.None
purposePurposeThe purpose of the DTO being configured (READ, WRITE, or COMPLETE). Defaults to Purpose.READ.READ

Returns:

TypeDescription
SelfA new DTOConfig instance with the specified include and purpose settings.
SelfAll other configuration parameters use their defaults.

global_exclude ​

python
global_exclude: FieldSpec | None = None

Explicitly exclude fields from the generated DTO and all its children. Implies everything else is included.

global_include ​

python
global_include: FieldSpec | None = None

Explicitly include fields from the generated DTO and all its children.

include ​

python
include: FieldSpec | None = None

Explicitly include fields from the generated DTO.

included_fields ​

python
included_fields: FieldSet = field(init=False)

is_field_included ​

python
is_field_included(field: FieldSelector | DTOFieldDefinition[Any, Any], scope: ConfigScope | None = None) -> bool

Whether a field is included per the include/exclude rules.

field is a field name or a DTOFieldDefinition. A bare str is treated as a non-relation field name.

partial ​

python
partial: bool | None = None

Make all field optional.

partial_default ​

python
partial_default: Any = None

Value given to a field left unset while partial is on.

purpose ​

python
purpose: Purpose

Configure the DTO for "read" or "write" operations.

scope ​

python
scope: DTOScope | None = None

tags ​

python
tags: set[str] = field(default_factory=set)

type_overrides ​

python
type_overrides: Mapping[Any, Any] = field(default_factory=dict)

Replacement types, keyed by either the field name or the type being replaced.

union ​

python
union(other: DTOConfig) -> DTOConfig

unset_sentinel ​

python
unset_sentinel: Any = DTOUnset

Marker separating a field set to None from one never provided.

with_base_annotations ​

python
with_base_annotations(base: type[Any]) -> DTOConfig

Merge type annotations from a base class into this DTOConfig.

Parameters:

NameTypeDescriptionDefault
basetype[Any]The base class to extract type annotations fromrequired

Returns:

TypeDescription
DTOConfigA new DTOConfig instance with:
DTOConfig- Type annotations from the base class merged into annotation_overrides
DTOConfig- Updated include set to include all fields if exclude is specified or include was "all"

The method handles two cases:

  1. When include is "all" or exclude is specified: All fields from the base class are included
  2. When specific fields are included: Only those fields are added to the include set