Mypy
Strawberry works with Mypy out of the
box thanks to
dataclass_transform .
No plugin is needed for standard Strawberry types, inputs, interfaces, enums,
scalars, or unions.
Pydantic integration
If you use strawberry.experimental.pydantic , add both the pydantic and
strawberry plugins to your mypy configuration:
[mypy]plugins = pydantic.mypy, strawberry.ext.mypy_plugin Or in pyproject.toml :
[tool.mypy]plugins = ["pydantic.mypy", "strawberry.ext.mypy_plugin"] The strawberry plugin synthesises __init__ , to_pydantic() and
from_pydantic() on pydantic-decorated classes so that mypy can see them.
Enums
The preferred way to register an enum is with the decorator:
from enum import Enumimport strawberry
@strawberry.enumclass IceCreamFlavour(Enum): VANILLA = "vanilla" STRAWBERRY = "strawberry" If you need to expose an existing enum under a different name or alias, use
Annotated instead of assigning strawberry.enum(IceCreamFlavour) to a
variable — mypy treats the latter as a value, not a type, so it cannot be used
in annotations.
from typing import Annotatedimport strawberry
MyIceCreamFlavour = Annotated[IceCreamFlavour, strawberry.enum(description="...")] MyIceCreamFlavour is a proper type alias that mypy and Pyright accept in
annotations.