strawberry
strawberry copied to clipboard
WIP - Fix `enum_value`
This PR will fix an issue that doesn't allow you from using Enums that use enum_value for defining their value. The issue comes from Enum(...) trying to find the enum value using it's value, but when using strawberry.enum_value the value is the enum value definition.
We can fix this by changing the value or by adding an __eq__ method, not sure which one is better.
The PR has only the tests :)
Codecov Report
Merging #2185 (9cf63a8) into main (76cf1d5) will not change coverage. The diff coverage is
n/a.
Additional details and impacted files
@@ Coverage Diff @@
## main #2185 +/- ##
=======================================
Coverage 98.19% 98.19%
=======================================
Files 162 162
Lines 6492 6492
Branches 1236 1236
=======================================
Hits 6375 6375
Misses 58 58
Partials 59 59
I think there is a better solution: a subclass of an enum and using class keyword arguments. Also with adapter function
would look like:
class Foo(strawberry.Enum, description="foo")
and for existing enum (metadata like description is added via function)
strawberry.Enum.adapt(enum, adapt_fn=foo)
Edit: I changed the function parameter name
in some way like the graphene Enum
I will upload a draft
see #2203
can be used like
from strawberry import StrawberryEnum
class Foo(str, StrawberryEnum, name="j"):
a = "test"
Limitation: needs type
the limitation has been lifted and it seems that only some small issues remain
Is there interest in my solution? Shall I continue working on it?
anyway: to remove the EnumValueDefinition you can create an enum subclass by enum_value. this will be directly used instead of creating an extra Value.
@devkral I'm really sorry I haven't answered you earlier!
I think I found an easier solution in #2306, let me know what you think