This is how you create a custom scalar now:
import base64
from typing import NewType
import strawberry
Base64 = strawberry.scalar(
NewType("Base64", bytes),
serialize=lambda v: base64.b64encode(v).decode("utf-8"),
parse_value=lambda v: base64.b64decode(v).encode("utf-8"),
)
Unfortunately this is can't be typed properly (See #3312, but I'd love to be wrong, I haven't spent too much time to check this)
If we can type this correctly we could think of implementing scalars using Annotated, like this:
import base64
from typing import NewType
import strawberry
Base64 = Annotated[
NewType("Base64", bytes),
strawberry.scalar(
serialize=lambda v: base64.b64encode(v).decode("utf-8"),
parse_value=lambda v: base64.b64decode(v).encode("utf-8"),
)
]
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