Configuration options
The mapper-wide configuration, and the configuration behind each generated type.
StrawchemyConfig
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) -> NoneGlobal configuration for Strawchemy.
auto_is_type_of
auto_is_type_of: bool = TrueAuto-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
auto_snake_case: bool = TrueAutomatically convert snake cased names to camel case
default_id_field_name
default_id_field_name: str = 'id'Name for primary key fields arguments on primary key resolvers.
deterministic_ordering
deterministic_ordering: bool = TrueForce deterministic ordering for list resolvers.
dialect
dialect: SupportedDialectdistinct_on
distinct_on: FieldSpec | None = NoneEnable/disable distinct on on list resolvers.
distinct_on_config
distinct_on_config: DTOConfigexclude
exclude: FieldSpec | None = NoneGlobally excluded fields.
execution_options
execution_options: dict[str, Any] | None = NoneSQLAlchemy execution options for strawberry operations.
field_config
field_config: DTOConfigfilter_overrides
filter_overrides: FilterMap | None = NoneOverride default filters with custom filters.
include
include: FieldSpec = 'all'Globally included fields.
inspector
inspector: SQLAlchemyGraphQLInspector = field(init=False)order_by
order_by: FieldSpec | None = NoneEnable/disable order by on list resolvers.
order_config
order_config: DTOConfigpagination
pagination: FieldSpec | None = NoneEnable/disable pagination on list resolvers.
pagination_config
pagination_config: DTOConfigpagination_default_limit
pagination_default_limit: int = 100Default pagination limit when pagination=True.
pagination_default_offset
pagination_default_offset: int = 0Default pagination offset when pagination=True.
repository_type
repository_type: AnyRepositoryType = StrawchemySyncRepositoryRepository class to use for auto resolvers.
session_getter
session_getter: AnySessionGetter = default_session_getterFunction to retrieve SQLAlchemy session from strawberry Info object.
strict
strict: bool = TrueWhen 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
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()) -> NoneControl the generated DTO.
Raises:
| Type | Description |
|---|---|
ValueError | If both aliases and alias_generator are provided. |
alias
alias(name: str) -> str | Nonealias_generator
alias_generator: Callable[[str], str] | None = NoneBuilds each field's alias from its name. Mutually exclusive with aliases.
aliases
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
annotation_overrides: dict[str, Any] = field(default_factory=dict)Replacement annotations, keyed by field name.
copy_with
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) -> DTOConfigCreate a copy of the DTOConfig with the specified changes.
exclude
exclude: FieldSpec | None = NoneExplicitly exclude fields from the generated DTO. Implies everything else is included.
exclude_defaults
exclude_defaults: bool = Falseexclude_from_scope
exclude_from_scope: bool = Falseexcluded_fields
excluded_fields: FieldSet = field(init=False)from_include
from_include(include: FieldSpec | Literal[False] | None = None, purpose: Purpose = Purpose.READ) -> SelfCreate 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:
| Name | Type | Description | Default |
|---|---|---|---|
include | FieldSpec | Literal[False] | None | The 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 |
purpose | Purpose | The purpose of the DTO being configured (READ, WRITE, or COMPLETE). Defaults to Purpose.READ. | READ |
Returns:
| Type | Description |
|---|---|
Self | A new DTOConfig instance with the specified include and purpose settings. |
Self | All other configuration parameters use their defaults. |
global_exclude
global_exclude: FieldSpec | None = NoneExplicitly exclude fields from the generated DTO and all its children. Implies everything else is included.
global_include
global_include: FieldSpec | None = NoneExplicitly include fields from the generated DTO and all its children.
include
include: FieldSpec | None = NoneExplicitly include fields from the generated DTO.
included_fields
included_fields: FieldSet = field(init=False)is_field_included
is_field_included(field: FieldSelector | DTOFieldDefinition[Any, Any], scope: ConfigScope | None = None) -> boolWhether 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
partial: bool | None = NoneMake all field optional.
partial_default
partial_default: Any = NoneValue given to a field left unset while partial is on.
purpose
purpose: PurposeConfigure the DTO for "read" or "write" operations.
scope
scope: DTOScope | None = Nonetags
tags: set[str] = field(default_factory=set)type_overrides
type_overrides: Mapping[Any, Any] = field(default_factory=dict)Replacement types, keyed by either the field name or the type being replaced.
union
union(other: DTOConfig) -> DTOConfigunset_sentinel
unset_sentinel: Any = DTOUnsetMarker separating a field set to None from one never provided.
with_base_annotations
with_base_annotations(base: type[Any]) -> DTOConfigMerge type annotations from a base class into this DTOConfig.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
base | type[Any] | The base class to extract type annotations from | required |
Returns:
| Type | Description |
|---|---|
DTOConfig | A 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:
- When include is "all" or exclude is specified: All fields from the base class are included
- When specific fields are included: Only those fields are added to the include set