Unsupported Root Model Error
Description
This error is thrown when a Pydantic RootModel is decorated with
@strawberry.pydantic.type , @strawberry.pydantic.input or
@strawberry.pydantic.interface , or when a field of a strawberry.pydantic
type uses one, for example the following code will throw this error:
import pydanticimport strawberry
@strawberry.pydantic.inputclass Tags(pydantic.RootModel[list[str]]): pass An unregistered RootModel field also raises the error when the schema is
built:
import pydanticimport strawberry
class Tags(pydantic.RootModel[list[str]]): pass
@strawberry.pydantic.inputclass CreatePostInput(pydantic.BaseModel): title: str tags: Tags
@strawberry.typeclass Query: ok: bool
schema = strawberry.Schema(query=Query, types=[CreatePostInput]) This happens because a RootModel holds a single value instead of fields, so it
canβt be a GraphQL object type or input.
A RootModel field can instead be exposed through a custom scalar registered in
the schemaβs scalar_map .
How to fix this error
You can fix this error by using the type of the root value instead of the
RootModel :
import pydanticimport strawberry
@strawberry.pydantic.inputclass CreatePostInput(pydantic.BaseModel): title: str tags: list[str]