In our project, we want to introduce an "alias" for a string, which is called CodeInput
. Creating a custom scalar as described in the docs yields a pyright error.
Creating a custom scalar
CodeInput = strawberry.scalar(
NewType("CodeInput", str),
serialize=lambda v: v,
parse_value=lambda v: v,
)
and checking it via pyright <file>
yields:
/home/tobias/repos/demo/backend/demo/graphql/types/codes.py
/home/tobias/repos/demobackend/demo/graphql/types/codes.py:53:13 - error: Type of "scalar" is partially unknown
Type of "scalar" is "Overload[(*, name: str | None = None, description: str | None = None, specified_by_url: str | None = None, serialize: (...) -> Unknown = identity, parse_value: ((...) -> Unknown) | None = None, parse_literal: ((...) -> Unknown) | None = None, directives: Iterable[object] = ()) -> ((_T@scalar) -> _T@scalar), (cls: _T@scalar, *, name: str | None = None, description: str | None = None, specified_by_url: str | None = None, serialize: (...) -> Unknown = identity, parse_value: ((...) -> Unknown) | None = None, parse_literal: ((...) -> Unknown) | None = None, directives: Iterable[object] = ()) -> _T@scalar]" (reportUnknownMemberType)
/home/tobias/repos/demo/backend/demo/graphql/types/codes.py:55:22 - error: Type of parameter "v" is unknown (reportUnknownLambdaType)
/home/tobias/repos/demo/backend/demo/graphql/types/codes.py:55:25 - error: Return type of lambda is unknown (reportUnknownLambdaType)
/home/tobias/repos/demo/backend/demo/graphql/types/codes.py:56:24 - error: Type of parameter "v" is unknown (reportUnknownLambdaType)
/home/tobias/repos/demo/backend/demo/graphql/types/codes.py:56:27 - error: Return type of lambda is unknown (reportUnknownLambdaType)
5 errors, 0 warnings, 0 informations
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