Skip to content

🍓 0.311.0

Choose a tag to compare

@botberry botberry released this 08 Mar 18:30
· 90 commits to main since this release

Enums can now be registered via Annotated. The preferred way is still using
@strawberry.enum as a decorator, but when you need to expose an existing enum
under a different name or alias, Annotated works as a proper type alias in all
type checkers:

from typing import Annotated
from enum import Enum
import strawberry


class IceCreamFlavour(Enum):
    VANILLA = "vanilla"
    STRAWBERRY = "strawberry"
    CHOCOLATE = "chocolate"


MyIceCreamFlavour = Annotated[
    IceCreamFlavour, strawberry.enum(description="Ice cream flavours")
]


@strawberry.type
class Query:
    @strawberry.field
    def flavour(self) -> MyIceCreamFlavour:
        return IceCreamFlavour.VANILLA

Releases contributed by @bellini666 via #4293