Skip to content
Open
Show file tree
Hide file tree
Changes from 6 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
3 changes: 3 additions & 0 deletions RELEASE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Release type: patch
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would this be a minor? It does more than just fixing, it also changes variable names

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree 100% with you, also will add a deprecated info on the release


Resolve TODO's about EnumDefinition by renaming it to StrawberryEnum
6 changes: 3 additions & 3 deletions strawberry/annotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,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 @@ -213,7 +213,7 @@ 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
except AttributeError:
Expand Down Expand Up @@ -386,7 +386,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 @@ -45,7 +45,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 @@ -551,7 +551,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 @@ -907,7 +907,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 @@ -373,7 +373,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 @@ -39,7 +39,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 @@ -183,7 +183,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 @@ -83,7 +83,7 @@ def get_type_by_name(
Union[
StrawberryObjectDefinition,
ScalarDefinition,
EnumDefinition,
StrawberryEnum,
StrawberryUnion,
]
]:
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_: Union[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 @@ -92,7 +92,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 @@ -443,7 +443,7 @@ def get_type_by_name(
Union[
StrawberryObjectDefinition,
ScalarDefinition,
EnumDefinition,
StrawberryEnum,
StrawberryUnion,
]
]:
Expand Down Expand Up @@ -918,7 +918,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 @@ -67,7 +67,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 @@ -157,7 +157,7 @@ def _get_thunk_mapping(
class CustomGraphQLEnumType(GraphQLEnumType):
def __init__(
self,
enum: EnumDefinition,
enum: StrawberryEnum,
*args: Any,
**kwargs: Any,
) -> None:
Expand Down Expand Up @@ -301,7 +301,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 @@ -869,7 +869,7 @@ def from_type(self, type_: Union[StrawberryType, type]) -> GraphQLNullableType:
if compat.is_graphql_generic(type_):
raise MissingTypesForGenericError(type_)

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 @@ -882,8 +882,8 @@ def from_type(self, type_: Union[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_._enum_definition # type: ignore
return self.from_enum(enum_definition)
if isinstance(type_, StrawberryObjectDefinition):
return self.from_object(type_)
Expand Down Expand Up @@ -1018,14 +1018,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: Union[
StrawberryObjectDefinition, EnumDefinition, ScalarDefinition, StrawberryUnion
StrawberryObjectDefinition, StrawberryEnum, ScalarDefinition, StrawberryUnion
]
implementation: GraphQLType

Expand Down
8 changes: 4 additions & 4 deletions strawberry/types/arguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,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 @@ -155,14 +155,14 @@ 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
enum_definition: StrawberryEnum = type_._enum_definition
return _is_leaf_type(enum_definition, scalar_registry)

return False
Expand Down Expand Up @@ -243,7 +243,7 @@ def convert_argument(
return convert_argument(value, type_.resolve_type(), scalar_registry, config)

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

if has_object_definition(type_):
Expand Down
2 changes: 1 addition & 1 deletion strawberry/types/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ def is_implemented_by(self, root: type[WithStrawberryObjectDefinition]) -> bool:

# 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:
# the StrawberryEnum class. This is why we do this check here:
if hasattr(real_concrete_type, "_enum_definition"):
real_concrete_type = real_concrete_type._enum_definition

Expand Down
6 changes: 3 additions & 3 deletions strawberry/types/enum.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class EnumValue:


@dataclasses.dataclass
class EnumDefinition(StrawberryType):
class StrawberryEnum(StrawberryType):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like my comment below, we also need to expose the deprecated version of this

Like in https://github.com/strawberry-graphql/strawberry/blob/main/strawberry/types/base.py#L456-L456

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, updating now!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated, @bellini666 , I use the same implementation we done in this PR #2836 .
Please let me now if you see a better way to do it!

wrapped_cls: EnumMeta
name: str
values: list[EnumValue]
Expand Down Expand Up @@ -151,7 +151,7 @@ def _process_enum(
)
values.append(value)

cls._enum_definition = EnumDefinition( # type: ignore
cls._enum_definition = StrawberryEnum( # type: ignore
wrapped_cls=cls,
name=name,
values=values,
Expand Down Expand Up @@ -238,4 +238,4 @@ def wrap(cls: EnumType) -> EnumType:
return wrap(cls)


__all__ = ["EnumDefinition", "EnumValue", "EnumValueDefinition", "enum", "enum_value"]
__all__ = ["EnumValue", "EnumValueDefinition", "StrawberryEnum", "enum", "enum_value"]
4 changes: 2 additions & 2 deletions tests/enums/test_enum.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import strawberry
from strawberry.exceptions import ObjectIsNotAnEnumError
from strawberry.types.base import get_object_definition
from strawberry.types.enum import EnumDefinition
from strawberry.types.enum import StrawberryEnum


def test_basic_enum():
Expand Down Expand Up @@ -58,7 +58,7 @@ def flavour_available(self, flavour: IceCreamFlavour) -> bool:

field = Query.__strawberry_definition__.fields[0]

assert isinstance(field.arguments[0].type, EnumDefinition)
assert isinstance(field.arguments[0].type, StrawberryEnum)


@pytest.mark.raises_strawberry_exception(
Expand Down
4 changes: 2 additions & 2 deletions tests/experimental/pydantic/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
StrawberryObjectDefinition,
StrawberryOptional,
)
from strawberry.types.enum import EnumDefinition
from strawberry.types.enum import StrawberryEnum
from strawberry.types.union import StrawberryUnion


Expand Down Expand Up @@ -575,7 +575,7 @@ class UserType:
assert field1.type is int

assert field2.python_name == "kind"
assert isinstance(field2.type, EnumDefinition)
assert isinstance(field2.type, StrawberryEnum)
assert field2.type.wrapped_cls is UserKind


Expand Down
Loading
Loading