Found while working on #391.
Under from __future__ import annotations, a strawchemy.field() annotation that references a plain strawberry type never resolves, so the schema fails to build:
from __future__ import annotations
@strawberry.type
class Plain:
name: str
@strawberry.type
class Query:
color_or_plain: ColorType | Plain = strawchemy.field()
UnresolvedFieldTypeError: Could not resolve the type of 'color_or_plain'. The same happens with a custom ErrorType subclass in a mutation union.
The annotation is evaluated against the strawchemy registry namespace only (StrawchemyField.type setter using self.registry_namespace in src/strawchemy/schema/field.py, and _annotation_namespace() in src/strawchemy/mapper.py), which does not contain types defined outside strawchemy.
Expected
Annotations resolve plain strawberry types from the module where the field is declared, as they do without postponed annotations.
Found while working on #391.
Under
from __future__ import annotations, astrawchemy.field()annotation that references a plain strawberry type never resolves, so the schema fails to build:UnresolvedFieldTypeError: Could not resolve the type of 'color_or_plain'. The same happens with a customErrorTypesubclass in a mutation union.The annotation is evaluated against the strawchemy registry namespace only (
StrawchemyField.typesetter usingself.registry_namespaceinsrc/strawchemy/schema/field.py, and_annotation_namespace()insrc/strawchemy/mapper.py), which does not contain types defined outside strawchemy.Expected
Annotations resolve plain strawberry types from the module where the field is declared, as they do without postponed annotations.