Classes decorated with @strawberry.scalar
do not allow classmethods of the class to be used at runtime.
Consider as an example the scalar:
@strawberry.scalar
class Timestamp(int):
"""An int representing the number of seconds before or after 1970-01-01-T00:00Z."""
@classmethod
def from_optional(cls, value: Optional[int]) -> Optional[Timestamp]:
return None if value is None else cls(value)
And related schema definition:
@strawberry.type
class MyData:
def start_time(self, t: Optional[int]) -> Optional[Timestamp]:
return Timestamp.from_optional(t)
Resolving the start_time
field will fail with the error
ERROR strawberry.execution:execute.py:249 'ScalarWrapper' object has no attribute 'from_optional'
.
It seems like ScalarWrapper does not preserve all relevant attributes of the wrapped class. I have observed that another common class wrapper @strawberry.type
does preserve classmethods correctly.
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