Skip to content
Open
Show file tree
Hide file tree
Changes from 33 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
a6224f4
Refactor enum handling: rename EnumDefinition to StrawberryEnum acros…
Ckk3 Sep 22, 2025
3d08e36
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 22, 2025
ccfc3fb
Update comments to reflect renaming of EnumDefinition to StrawberryEnum
Ckk3 Sep 22, 2025
4b46d69
Fix type check for StrawberryEnum in NameConverter
Ckk3 Sep 22, 2025
ec4a439
Add RELEASE.md
Ckk3 Sep 22, 2025
04a042c
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 22, 2025
5b7b16a
Fix typo in RELEASE.md regarding EnumDefinition renaming
Ckk3 Sep 22, 2025
9de176a
Refactor enum definition references to use __strawberry_definition__ …
Ckk3 Sep 22, 2025
0e5bd53
Refactor enum handling to use __strawberry_definition__ instead of _e…
Ckk3 Sep 23, 2025
c51a46c
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 23, 2025
39b863a
Enhance StrawberryObjectDefinition to handle StrawberryEnum instances…
Ckk3 Sep 23, 2025
00372fa
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 23, 2025
79622de
Use cast to ensure type safety for __strawberry_definition__ in Straw…
Ckk3 Sep 27, 2025
ad2b825
Merge branch 'issue-3998' of https://github.com/Ckk3/strawberry into …
Ckk3 Sep 27, 2025
5fd2888
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 27, 2025
f21bcca
updated release.md to minor and add deprecation info
Ckk3 Sep 28, 2025
fc97abe
Add deprecation warnings for _enum_definition and update tests for al…
Ckk3 Sep 28, 2025
e50d386
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 28, 2025
7dd1461
fix deprecated typing error
Ckk3 Sep 28, 2025
f8bd6b3
Refactor import statements and clean up TYPE_CHECKING usage in enum.py
Ckk3 Sep 28, 2025
81e3121
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 28, 2025
66fafe6
Refactor type handling in real_concrete_type
Ckk3 Sep 30, 2025
21ae6d5
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 30, 2025
0433b9d
Simplify conditional check for StrawberryEnum in StrawberryObjectDefi…
Ckk3 Sep 30, 2025
aec0b97
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 30, 2025
9d5dbb4
Add GraphQL query for retrieving node by ID and corresponding test case
Ckk3 Oct 2, 2025
9bad777
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 2, 2025
23bd876
Merge remote-tracking branch 'origin/main' into issue-3998
Ckk3 Oct 18, 2025
60d69f6
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 18, 2025
7bfe977
Merge remote-tracking branch 'origin/main' into issue-3998
Ckk3 Oct 25, 2025
4ddfc9d
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 25, 2025
a5b713d
refactor: remove unused GraphQL query and related test for relay node ID
Ckk3 Oct 26, 2025
ad8cc5b
refactor: update is_enum function to use the "|" syntax for type hints
Ckk3 Oct 26, 2025
d9a91ad
Merge remote-tracking branch 'origin/main' into issue-3998
Ckk3 Oct 27, 2025
ac2fbdb
fix: standardize multiplication symbol in stadium creation documentat…
Ckk3 Oct 27, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions RELEASE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Release type: minor

## Deprecation Alert
- **Deprecated**: Replaced `_enum_definition` with `__strawberry_definition__`. The former will continue to work but will raise a deprecation warning.

### Other Changes
- **Renamed**: Changed `EnumDefinition` to `StrawberryEnum` to standardize internal naming patterns.
- These updates improve naming consistency and address previously identified TODOs.
10 changes: 5 additions & 5 deletions strawberry/annotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
get_object_definition,
has_object_definition,
)
from strawberry.types.enum import EnumDefinition
from strawberry.types.enum import StrawberryEnum
from strawberry.types.enum import enum as strawberry_enum
from strawberry.types.lazy_type import LazyType
from strawberry.types.maybe import _annotation_is_maybe
Expand Down Expand Up @@ -215,11 +215,11 @@ def create_concrete_type(self, evaled_type: type) -> type:
return evaled_type.__strawberry_definition__.resolve_generic(evaled_type)
raise ValueError(f"Not supported {evaled_type}")

def create_enum(self, evaled_type: Any) -> EnumDefinition:
def create_enum(self, evaled_type: Any) -> StrawberryEnum:
try:
return evaled_type._enum_definition
return evaled_type.__strawberry_definition__
except AttributeError:
return strawberry_enum(evaled_type)._enum_definition
return strawberry_enum(evaled_type).__strawberry_definition__

def create_list(self, evaled_type: Any) -> StrawberryList:
item_type, *_ = get_args(evaled_type)
Expand Down Expand Up @@ -388,7 +388,7 @@ def _is_strawberry_type(cls, evaled_type: Any) -> bool:
# Prevent import cycles
from strawberry.types.union import StrawberryUnion

if isinstance(evaled_type, EnumDefinition):
if isinstance(evaled_type, StrawberryEnum):
return True
elif _is_input_type(evaled_type): # TODO: Replace with StrawberryInputObject
return True
Expand Down
6 changes: 3 additions & 3 deletions strawberry/codegen/query_codegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
get_object_definition,
has_object_definition,
)
from strawberry.types.enum import EnumDefinition
from strawberry.types.enum import StrawberryEnum
from strawberry.types.lazy_type import LazyType
from strawberry.types.scalar import ScalarDefinition, ScalarWrapper
from strawberry.types.union import StrawberryUnion
Expand Down Expand Up @@ -543,7 +543,7 @@ def _get_field_type(
if isinstance(field_type, ScalarDefinition):
return self._collect_scalar(field_type, None)

if isinstance(field_type, EnumDefinition):
if isinstance(field_type, StrawberryEnum):
return self._collect_enum(field_type)

raise ValueError(f"Unsupported type: {field_type}") # pragma: no cover
Expand Down Expand Up @@ -897,7 +897,7 @@ def _collect_scalar(

return graphql_scalar

def _collect_enum(self, enum: EnumDefinition) -> GraphQLEnum:
def _collect_enum(self, enum: StrawberryEnum) -> GraphQLEnum:
graphql_enum = GraphQLEnum(
enum.name,
[value.name for value in enum.values],
Expand Down
4 changes: 2 additions & 2 deletions strawberry/experimental/pydantic/conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
StrawberryOptional,
has_object_definition,
)
from strawberry.types.enum import EnumDefinition
from strawberry.types.enum import StrawberryEnum
from strawberry.types.union import StrawberryUnion

if TYPE_CHECKING:
Expand Down Expand Up @@ -40,7 +40,7 @@ def _convert_from_pydantic_to_strawberry_type(
return _convert_from_pydantic_to_strawberry_type(
option_type, data_from_model=data, extra=extra
)
if isinstance(type_, EnumDefinition):
if isinstance(type_, StrawberryEnum):
return data
if isinstance(type_, StrawberryList):
items = []
Expand Down
4 changes: 2 additions & 2 deletions strawberry/federation/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
from strawberry.federation.schema_directives import ComposeDirective
from strawberry.schema.config import StrawberryConfig
from strawberry.schema_directive import StrawberrySchemaDirective
from strawberry.types.enum import EnumDefinition
from strawberry.types.enum import StrawberryEnum
from strawberry.types.scalar import ScalarDefinition, ScalarWrapper


Expand Down Expand Up @@ -372,7 +372,7 @@ def _has_federation_keys(
definition: Union[
StrawberryObjectDefinition,
"ScalarDefinition",
"EnumDefinition",
"StrawberryEnum",
"StrawberryUnion",
],
) -> bool:
Expand Down
4 changes: 2 additions & 2 deletions strawberry/printer/printer.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
StrawberryObjectDefinition,
has_object_definition,
)
from strawberry.types.enum import EnumDefinition
from strawberry.types.enum import StrawberryEnum
from strawberry.types.scalar import ScalarWrapper
from strawberry.types.unset import UNSET

Expand Down Expand Up @@ -182,7 +182,7 @@ def print_schema_directive(
if hasattr(f_type, "_scalar_definition"):
extras.types.add(cast("type", f_type))

if isinstance(f_type, EnumDefinition):
if isinstance(f_type, StrawberryEnum):
extras.types.add(cast("type", f_type))

return f" @{gql_directive.name}{params}"
Expand Down
4 changes: 2 additions & 2 deletions strawberry/schema/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
StrawberryObjectDefinition,
WithStrawberryObjectDefinition,
)
from strawberry.types.enum import EnumDefinition
from strawberry.types.enum import StrawberryEnum
from strawberry.types.graphql import OperationType
from strawberry.types.scalar import ScalarDefinition
from strawberry.types.union import StrawberryUnion
Expand Down Expand Up @@ -82,7 +82,7 @@ def get_type_by_name(
) -> (
StrawberryObjectDefinition
| ScalarDefinition
| EnumDefinition
| StrawberryEnum
| StrawberryUnion
| None
):
Expand Down
6 changes: 5 additions & 1 deletion strawberry/schema/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from strawberry.scalars import is_scalar as is_strawberry_scalar
from strawberry.types.base import StrawberryType, has_object_definition
from strawberry.types.enum import StrawberryEnum

# TypeGuard is only available in typing_extensions => 3.10, we don't want
# to force updates to the typing_extensions package so we only use it when
Expand Down Expand Up @@ -36,7 +37,10 @@ def is_scalar(


def is_enum(type_: StrawberryType | type) -> TypeGuard[type]:
return hasattr(type_, "_enum_definition")
if hasattr(type_, "__strawberry_definition__"):
return isinstance(type_.__strawberry_definition__, StrawberryEnum)

return False


def is_schema_directive(type_: StrawberryType | type) -> TypeGuard[type]:
Expand Down
10 changes: 5 additions & 5 deletions strawberry/schema/name_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
StrawberryOptional,
has_object_definition,
)
from strawberry.types.enum import EnumDefinition, EnumValue
from strawberry.types.enum import EnumValue, StrawberryEnum
from strawberry.types.lazy_type import LazyType
from strawberry.types.scalar import ScalarDefinition
from strawberry.types.union import StrawberryUnion
Expand Down Expand Up @@ -45,7 +45,7 @@ def from_type(
) -> str:
if isinstance(type_, (StrawberryDirective, StrawberrySchemaDirective)):
return self.from_directive(type_)
if isinstance(type_, EnumDefinition): # TODO: Replace with StrawberryEnum
if isinstance(type_, StrawberryEnum):
return self.from_enum(type_)
if isinstance(type_, StrawberryObjectDefinition):
if type_.is_input:
Expand Down Expand Up @@ -78,10 +78,10 @@ def from_input_object(self, input_type: StrawberryObjectDefinition) -> str:
def from_interface(self, interface: StrawberryObjectDefinition) -> str:
return self.from_object(interface)

def from_enum(self, enum: EnumDefinition) -> str:
def from_enum(self, enum: StrawberryEnum) -> str:
return enum.name

def from_enum_value(self, enum: EnumDefinition, enum_value: EnumValue) -> str:
def from_enum_value(self, enum: StrawberryEnum, enum_value: EnumValue) -> str:
return enum_value.name

def from_directive(
Expand Down Expand Up @@ -152,7 +152,7 @@ def get_name_from_type(self, type_: StrawberryType | type) -> str:
if isinstance(type_, LazyType):
type_ = type_.resolve_type()

if isinstance(type_, EnumDefinition):
if isinstance(type_, StrawberryEnum):
name = type_.name
elif isinstance(type_, StrawberryUnion):
name = type_.graphql_name if type_.graphql_name else self.from_union(type_)
Expand Down
6 changes: 3 additions & 3 deletions strawberry/schema/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@

from strawberry.directive import StrawberryDirective
from strawberry.types.base import StrawberryType
from strawberry.types.enum import EnumDefinition
from strawberry.types.enum import StrawberryEnum
from strawberry.types.field import StrawberryField
from strawberry.types.scalar import ScalarDefinition, ScalarWrapper
from strawberry.types.union import StrawberryUnion
Expand Down Expand Up @@ -438,7 +438,7 @@ def get_type_by_name(
) -> (
StrawberryObjectDefinition
| ScalarDefinition
| EnumDefinition
| StrawberryEnum
| StrawberryUnion
| None
):
Expand Down Expand Up @@ -913,7 +913,7 @@ def _resolve_node_ids(self) -> None:
for concrete_type in self.schema_converter.type_map.values():
type_def = concrete_type.definition

# This can be a TypeDefinition, EnumDefinition, ScalarDefinition
# This can be a TypeDefinition, StrawberryEnum, ScalarDefinition
# or UnionDefinition
if not isinstance(type_def, StrawberryObjectDefinition):
continue
Expand Down
16 changes: 8 additions & 8 deletions strawberry/schema/schema_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
has_object_definition,
)
from strawberry.types.cast import get_strawberry_type_cast
from strawberry.types.enum import EnumDefinition
from strawberry.types.enum import StrawberryEnum
from strawberry.types.field import UNRESOLVED
from strawberry.types.lazy_type import LazyType
from strawberry.types.private import is_private
Expand Down Expand Up @@ -156,7 +156,7 @@ def _get_thunk_mapping(
class CustomGraphQLEnumType(GraphQLEnumType):
def __init__(
self,
enum: EnumDefinition,
enum: StrawberryEnum,
*args: Any,
**kwargs: Any,
) -> None:
Expand Down Expand Up @@ -300,7 +300,7 @@ def from_argument(self, argument: StrawberryArgument) -> GraphQLArgument:
},
)

def from_enum(self, enum: EnumDefinition) -> CustomGraphQLEnumType:
def from_enum(self, enum: StrawberryEnum) -> CustomGraphQLEnumType:
enum_name = self.config.name_converter.from_type(enum)

assert enum_name is not None
Expand Down Expand Up @@ -874,7 +874,7 @@ def from_type(self, type_: StrawberryType | type) -> GraphQLNullableType:
if len(args) >= 2 and isinstance(args[1], StrawberryUnion):
type_ = args[1]

if isinstance(type_, EnumDefinition): # TODO: Replace with StrawberryEnum
if isinstance(type_, StrawberryEnum):
return self.from_enum(type_)
if compat.is_input_type(type_): # TODO: Replace with StrawberryInputObject
return self.from_input_object(type_)
Expand All @@ -887,8 +887,8 @@ def from_type(self, type_: StrawberryType | type) -> GraphQLNullableType:
return self.from_interface(type_definition)
if has_object_definition(type_):
return self.from_object(type_.__strawberry_definition__)
if compat.is_enum(type_): # TODO: Replace with StrawberryEnum
enum_definition: EnumDefinition = type_._enum_definition # type: ignore
if compat.is_enum(type_):
enum_definition: StrawberryEnum = type_.__strawberry_definition__ # type: ignore
return self.from_enum(enum_definition)
if isinstance(type_, StrawberryObjectDefinition):
return self.from_object(type_)
Expand Down Expand Up @@ -1023,14 +1023,14 @@ def validate_same_type_definition(

if isinstance(second_type_definition, StrawberryObjectDefinition):
first_origin = second_type_definition.origin
elif isinstance(second_type_definition, EnumDefinition):
elif isinstance(second_type_definition, StrawberryEnum):
first_origin = second_type_definition.wrapped_cls
else:
first_origin = None

if isinstance(first_type_definition, StrawberryObjectDefinition):
second_origin = first_type_definition.origin
elif isinstance(first_type_definition, EnumDefinition):
elif isinstance(first_type_definition, StrawberryEnum):
second_origin = first_type_definition.wrapped_cls
else:
second_origin = None
Expand Down
4 changes: 2 additions & 2 deletions strawberry/schema/types/concrete_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

if TYPE_CHECKING:
from strawberry.types.base import StrawberryObjectDefinition
from strawberry.types.enum import EnumDefinition
from strawberry.types.enum import StrawberryEnum
from strawberry.types.scalar import ScalarDefinition
from strawberry.types.union import StrawberryUnion

Expand All @@ -17,7 +17,7 @@
@dataclasses.dataclass
class ConcreteType:
definition: (
StrawberryObjectDefinition | EnumDefinition | ScalarDefinition | StrawberryUnion
StrawberryObjectDefinition | StrawberryEnum | ScalarDefinition | StrawberryUnion
)
implementation: GraphQLType

Expand Down
14 changes: 6 additions & 8 deletions strawberry/types/arguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
StrawberryOptional,
has_object_definition,
)
from strawberry.types.enum import EnumDefinition
from strawberry.types.enum import StrawberryEnum
from strawberry.types.lazy_type import LazyType, StrawberryLazyReference
from strawberry.types.maybe import Some
from strawberry.types.unset import UNSET as _deprecated_UNSET # noqa: N811
Expand Down Expand Up @@ -154,16 +154,12 @@ def _is_leaf_type(
if is_scalar(type_, scalar_registry):
return True

if isinstance(type_, EnumDefinition):
if isinstance(type_, StrawberryEnum):
return True

if isinstance(type_, LazyType):
return _is_leaf_type(type_.resolve_type(), scalar_registry)

if hasattr(type_, "_enum_definition"):
enum_definition: EnumDefinition = type_._enum_definition
return _is_leaf_type(enum_definition, scalar_registry)

return False


Expand Down Expand Up @@ -241,8 +237,10 @@ def convert_argument(
if isinstance(type_, LazyType):
return convert_argument(value, type_.resolve_type(), scalar_registry, config)

if hasattr(type_, "_enum_definition"):
enum_definition: EnumDefinition = type_._enum_definition
if hasattr(type_, "__strawberry_definition__") and isinstance(
type_.__strawberry_definition__, StrawberryEnum
):
enum_definition: StrawberryEnum = type_.__strawberry_definition__
return convert_argument(value, enum_definition, scalar_registry, config)

if has_object_definition(type_):
Expand Down
17 changes: 11 additions & 6 deletions strawberry/types/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,15 +202,15 @@ def has_object_definition(
obj: Any,
) -> TypeGuard[type[WithStrawberryObjectDefinition]]:
if hasattr(obj, "__strawberry_definition__"):
return True
return isinstance(obj.__strawberry_definition__, StrawberryObjectDefinition)
# TODO: Generics remove dunder members here, so we inject it here.
# Would be better to avoid it somehow.
# https://github.com/python/cpython/blob/3a314f7c3df0dd7c37da7d12b827f169ee60e1ea/Lib/typing.py#L1152
if is_concrete_generic(obj):
concrete = obj.__origin__
if hasattr(concrete, "__strawberry_definition__"):
obj.__strawberry_definition__ = concrete.__strawberry_definition__
return True
return isinstance(obj.__strawberry_definition__, StrawberryObjectDefinition)
return False


Expand Down Expand Up @@ -419,13 +419,18 @@ def is_implemented_by(self, root: type[WithStrawberryObjectDefinition]) -> bool:
continue

# Check if the expected type matches the type found on the type_map
real_concrete_type = type(value)
from strawberry.types.enum import StrawberryEnum

real_concrete_type: type | StrawberryEnum = type(value)

# TODO: uniform type var map, at the moment we map object types
# to their class (not to TypeDefinition) while we map enum to
# the EnumDefinition class. This is why we do this check here:
if hasattr(real_concrete_type, "_enum_definition"):
real_concrete_type = real_concrete_type._enum_definition
# the StrawberryEnum class. This is why we do this check here:

if hasattr(real_concrete_type, "__strawberry_definition__") and isinstance(
real_concrete_type.__strawberry_definition__, StrawberryEnum
):
real_concrete_type = real_concrete_type.__strawberry_definition__

if (
isinstance(expected_concrete_type, type)
Expand Down
Loading
Loading