Add way of using pydantic model scalars without manually defining fields - just by using strawberry.auto
I have a pydantic model, lets say:
class SomeNameModel(pydantic.BaseModel):
name: str
number: int
And I have a scalar:
@strawberry.scalar(
name='SomeName',
serialize=marshal_some_name,
parse_value=unmarshal_some_name,
)
class SomeName(SomeNameModel):
"""SomeName scalar."""
I have a model which has uses that scalar:
class User(pydantic.BaseModel):
some_name: SomeNameModel
When I'm trying to create a type from it:
@strawberry.experimental.pydantic.type(
model=User,
)
class UserType:
some_name: strawberry.auto
I'm getting an error:
Cannot find a Strawberry Type for <class 'SomeNameModel'> did you forget to register it?
If I change User
to:
class User(pydantic.BaseModel):
some_name: SomeName
I have a pydantic error:
RuntimeError: error checking inheritance of <strawberry.custom_scalar.ScalarWrapper object at 0x10adc2ce0> (type: ScalarWrapper)
However, this works (manual annotation of type):
@strawberry.experimental.pydantic.type(
model=User,
)
class UserType:
some_name: SomeName
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too