Skip to content

Configuration ​

Pass options as a StrawchemyConfig to the Strawchemy instance; they apply to every type and field the mapper generates. A repository you build yourself in a custom resolver doesn't read them: pass session_getter, deterministic_ordering or execution_options to its constructor.

Configuration options ​

OptionTypeDefaultDescription
dialectSupportedDialectDatabase dialect: "postgresql", "mysql" or "sqlite".
session_getterCallable[[Info], Session | AsyncSession]default_session_getterFunction that retrieves the SQLAlchemy session from the strawberry Info object. The default reads session from info.context (attribute or key), then from info.context.request.
auto_snake_caseboolTrueConvert snake case names to camel case in the GraphQL schema.
repository_typetype[StrawchemySyncRepository | StrawchemyAsyncRepository]StrawchemySyncRepositoryRepository class to use for auto resolvers.
filter_overridesOrderedDict[tuple[type, ...], type[GraphQLComparison]]NoneReplace the default filters for specific column types with custom filter implementations.
execution_optionsdict[str, Any]NoneSQLAlchemy execution options for repository operations, passed to SQLAlchemy's execution_options() method.
default_id_field_namestr"id"Name of the primary key argument on primary key resolvers.
deterministic_orderingboolTrueAppend the primary key, ascending, to any list query with no explicit orderBy, so paginated results return in a stable order across pages.
strictboolTrueWhen True, a column whose Python type hint has no GraphQL mapping (arbitrary class, Pydantic model without a Strawberry wrapper, TypedDict, opaque JSONB type) fails the schema build.
auto_is_type_ofboolTrueAuto-generate is_type_of (an isinstance check against the model) on mapped types, so they work as GraphQL union/interface members with no extra code.
includeFieldSpec"all"Fields included by default across every mapped type, unless a decorator overrides it with its own include.
excludeFieldSpec | NoneNoneFields excluded by default across every mapped type, unless a decorator overrides it with its own exclude.
paginationFieldSpec | NoneNoneEnable/disable pagination on list resolvers by default. Set to "all" to enable pagination on all list fields.
order_byFieldSpec | NoneNoneEnable/disable order by on list resolvers by default. Set to "all" to enable ordering on all list fields.
distinct_onFieldSpec | NoneNoneEnable/disable a distinctOn argument on list resolvers by default. Set to "all" to enable it on all list fields; native on PostgreSQL, emulated elsewhere.
pagination_default_limitint100Default pagination limit when pagination=True.
pagination_default_offsetint0Default pagination offset when pagination=True.

Session getter ​

python
from strawchemy import Strawchemy, StrawchemyConfig


def get_session_from_context(info):
    return info.context.db_session


strawchemy = Strawchemy(
    StrawchemyConfig(
        "postgresql",
        session_getter=get_session_from_context,
    )
)

The configuration reference lists every option with its type and default.