We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
TypeError: Forward references must evaluate to types.
So I am running Strawberry with Fastapi

## Describe the Bug

I have a schema like this:

```
from __future__ import annotations
from enum import Enum
import strawberry
import datetime
from strawberry.scalars import JSON

@strawberry.enum
class Sex(Enum):
    male = "Male"
    female ="Female"

@strawberry.type
class PersonBase:
    name: JSON | None
    sex: Sex | None

@strawberry.type
class Client(PersonBase):
    firm: Firm | None = None


```
 When I try to run the server it throws back an error:

```
  File "C:\Users\0\Desktop\Fastapi\Test\.\app\main.py", line 14, in <module>
    from app.schema import schema
  File "C:\Users\0\Desktop\Fastapi\Test\.\app\schema.py", line 624, in <module>
    schema = strawberry.Schema(query=Query, mutation = Mutation)
  File "C:\Users\0\Envs\Fastapi\lib\site-packages\strawberry\schema\schema.py", line 115, in __init__
    self._schema = GraphQLSchema(
  File "C:\Users\0\Envs\Fastapi\lib\site-packages\graphql\type\schema.py", line 224, in __init__
    collect_referenced_types(query)
  File "C:\Users\0\Envs\Fastapi\lib\site-packages\graphql\type\schema.py", line 433, in collect_referenced_types
    collect_referenced_types(field.type)
  File "C:\Users\0\Envs\Fastapi\lib\site-packages\graphql\type\schema.py", line 433, in collect_referenced_types
    collect_referenced_types(field.type)
  File "C:\Users\0\Envs\Fastapi\lib\site-packages\graphql\type\schema.py", line 432, in collect_referenced_types
    for field in named_type.fields.values():
  File "C:\Users\0\AppData\Local\Programs\Python\Python310\lib\functools.py", line 970, in __get__
    val = self.func(instance)
  File "C:\Users\0\Envs\Fastapi\lib\site-packages\graphql\type\definition.py", line 811, in fields
    raise cls(f"{self.name} fields cannot be resolved. {error}") from error
TypeError: Client fields cannot be resolved. Forward references must evaluate to types. Got <strawberry.type.StrawberryOptional object at 0x000002C85C5F5990>.
```
Note that if I change one thing like this making a required name field with a string the error is resolved

```
@strawberry.type
class Client(PersonBase):
    firm: Firm | None = None
    name: str | None
```

But if I put PersonBase into the model like this, it still throws an error even though the name field is required as JSON.

```
class Client:
    firm: Firm | None = None
    name: JSON | None
    sex: Sex | None
```


## System Information

 - Operating system: Windows 10
 - Strawberry version (if applicable): strawberry-graphql==0.139.0

## Additional Context

Not sure if this is an bug or I did something wrong but I find this behavior strange because the JSON and Enum are both scalars but required and they triggered a type error.


<!-- POLAR PLEDGE BADGE START -->
## Upvote & Fund

- We're using [Polar.sh](https://polar.sh/strawberry-graphql) so you can upvote and help fund this issue.
- We receive the funding once the issue is completed & confirmed by you.
- Thank you in advance for helping prioritize & fund our backlog.

<a href="https://polar.sh/strawberry-graphql/strawberry/issues/2465">
<picture>
  <source media="(prefers-color-scheme: dark)" srcset="https://polar.sh/api/github/strawberry-graphql/strawberry/issues/2465/pledge.svg?darkmode=1">
  <img alt="Fund with Polar" src="https://polar.sh/api/github/strawberry-graphql/strawberry/issues/2465/pledge.svg">
</picture>
</a>
<!-- POLAR PLEDGE BADGE END -->


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `strawberry/custom_scalar.py`
Content:
```
1 from __future__ import annotations
2 
3 import sys
4 from dataclasses import dataclass
5 from typing import (
6     TYPE_CHECKING,
7     Any,
8     Callable,
9     Iterable,
10     Mapping,
11     NewType,
12     Optional,
13     Type,
14     TypeVar,
15     Union,
16     overload,
17 )
18 
19 from strawberry.exceptions import InvalidUnionTypeError
20 from strawberry.type import StrawberryOptional, StrawberryType
21 
22 from .utils.str_converters import to_camel_case
23 
24 if TYPE_CHECKING:
25     from graphql import GraphQLScalarType
26 
27 
28 # in python 3.10+ NewType is a class
29 if sys.version_info >= (3, 10):
30     _T = TypeVar("_T", bound=Union[type, NewType])
31 else:
32     _T = TypeVar("_T", bound=type)
33 
34 
35 def identity(x: _T) -> _T:
36     return x
37 
38 
39 @dataclass
40 class ScalarDefinition(StrawberryType):
41     name: str
42     description: Optional[str]
43     specified_by_url: Optional[str]
44     serialize: Optional[Callable]
45     parse_value: Optional[Callable]
46     parse_literal: Optional[Callable]
47     directives: Iterable[object] = ()
48 
49     # Optionally store the GraphQLScalarType instance so that we don't get
50     # duplicates
51     implementation: Optional[GraphQLScalarType] = None
52 
53     # used for better error messages
54     _source_file: Optional[str] = None
55     _source_line: Optional[int] = None
56 
57     def copy_with(
58         self, type_var_map: Mapping[TypeVar, Union[StrawberryType, type]]
59     ) -> Union[StrawberryType, type]:
60         return super().copy_with(type_var_map)  # type: ignore[safe-super]
61 
62     @property
63     def is_generic(self) -> bool:
64         return False
65 
66 
67 class ScalarWrapper:
68     _scalar_definition: ScalarDefinition
69 
70     def __init__(self, wrap: Callable[[Any], Any]):
71         self.wrap = wrap
72 
73     def __call__(self, *args: str, **kwargs: Any):
74         return self.wrap(*args, **kwargs)
75 
76     def __or__(self, other: Union[StrawberryType, type]) -> StrawberryType:
77         if other is None:
78             # Return the correct notation when using `StrawberryUnion | None`.
79             return StrawberryOptional(of_type=self)
80 
81         # Raise an error in any other case.
82         # There is Work in progress to deal with more merging cases, see:
83         # https://github.com/strawberry-graphql/strawberry/pull/1455
84         raise InvalidUnionTypeError(str(other), self.wrap)
85 
86 
87 def _process_scalar(
88     cls: Type[_T],
89     *,
90     name: Optional[str] = None,
91     description: Optional[str] = None,
92     specified_by_url: Optional[str] = None,
93     serialize: Optional[Callable] = None,
94     parse_value: Optional[Callable] = None,
95     parse_literal: Optional[Callable] = None,
96     directives: Iterable[object] = (),
97 ):
98     from strawberry.exceptions.handler import should_use_rich_exceptions
99 
100     name = name or to_camel_case(cls.__name__)
101 
102     _source_file = None
103     _source_line = None
104 
105     if should_use_rich_exceptions():
106         frame = sys._getframe(3)
107 
108         _source_file = frame.f_code.co_filename
109         _source_line = frame.f_lineno
110 
111     wrapper = ScalarWrapper(cls)
112     wrapper._scalar_definition = ScalarDefinition(
113         name=name,
114         description=description,
115         specified_by_url=specified_by_url,
116         serialize=serialize,
117         parse_literal=parse_literal,
118         parse_value=parse_value,
119         directives=directives,
120         _source_file=_source_file,
121         _source_line=_source_line,
122     )
123 
124     return wrapper
125 
126 
127 @overload
128 def scalar(
129     *,
130     name: Optional[str] = None,
131     description: Optional[str] = None,
132     specified_by_url: Optional[str] = None,
133     serialize: Callable = identity,
134     parse_value: Optional[Callable] = None,
135     parse_literal: Optional[Callable] = None,
136     directives: Iterable[object] = (),
137 ) -> Callable[[_T], _T]:
138     ...
139 
140 
141 @overload
142 def scalar(
143     cls: _T,
144     *,
145     name: Optional[str] = None,
146     description: Optional[str] = None,
147     specified_by_url: Optional[str] = None,
148     serialize: Callable = identity,
149     parse_value: Optional[Callable] = None,
150     parse_literal: Optional[Callable] = None,
151     directives: Iterable[object] = (),
152 ) -> _T:
153     ...
154 
155 
156 # FIXME: We are tricking pyright into thinking that we are returning the given type
157 # here or else it won't let us use any custom scalar to annotate attributes in
158 # dataclasses/types. This should be properly solved when implementing StrawberryScalar
159 def scalar(
160     cls=None,
161     *,
162     name: Optional[str] = None,
163     description: Optional[str] = None,
164     specified_by_url: Optional[str] = None,
165     serialize: Callable = identity,
166     parse_value: Optional[Callable] = None,
167     parse_literal: Optional[Callable] = None,
168     directives: Iterable[object] = (),
169 ) -> Any:
170     """Annotates a class or type as a GraphQL custom scalar.
171 
172     Example usages:
173 
174     >>> strawberry.scalar(
175     >>>     datetime.date,
176     >>>     serialize=lambda value: value.isoformat(),
177     >>>     parse_value=datetime.parse_date
178     >>> )
179 
180     >>> Base64Encoded = strawberry.scalar(
181     >>>     NewType("Base64Encoded", bytes),
182     >>>     serialize=base64.b64encode,
183     >>>     parse_value=base64.b64decode
184     >>> )
185 
186     >>> @strawberry.scalar(
187     >>>     serialize=lambda value: ",".join(value.items),
188     >>>     parse_value=lambda value: CustomList(value.split(","))
189     >>> )
190     >>> class CustomList:
191     >>>     def __init__(self, items):
192     >>>         self.items = items
193 
194     """
195 
196     if parse_value is None:
197         parse_value = cls
198 
199     def wrap(cls: Type):
200         return _process_scalar(
201             cls,
202             name=name,
203             description=description,
204             specified_by_url=specified_by_url,
205             serialize=serialize,
206             parse_value=parse_value,
207             parse_literal=parse_literal,
208             directives=directives,
209         )
210 
211     if cls is None:
212         return wrap
213 
214     return wrap(cls)
215
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/strawberry/custom_scalar.py b/strawberry/custom_scalar.py
--- a/strawberry/custom_scalar.py
+++ b/strawberry/custom_scalar.py
@@ -17,7 +17,7 @@
 )
 
 from strawberry.exceptions import InvalidUnionTypeError
-from strawberry.type import StrawberryOptional, StrawberryType
+from strawberry.type import StrawberryType
 
 from .utils.str_converters import to_camel_case
 
@@ -76,7 +76,7 @@
     def __or__(self, other: Union[StrawberryType, type]) -> StrawberryType:
         if other is None:
             # Return the correct notation when using `StrawberryUnion | None`.
-            return StrawberryOptional(of_type=self)
+            return Optional[self]
 
         # Raise an error in any other case.
         # There is Work in progress to deal with more merging cases, see:

{"golden_diff": "diff --git a/strawberry/custom_scalar.py b/strawberry/custom_scalar.py\n--- a/strawberry/custom_scalar.py\n+++ b/strawberry/custom_scalar.py\n@@ -17,7 +17,7 @@\n )\n \n from strawberry.exceptions import InvalidUnionTypeError\n-from strawberry.type import StrawberryOptional, StrawberryType\n+from strawberry.type import StrawberryType\n \n from .utils.str_converters import to_camel_case\n \n@@ -76,7 +76,7 @@\n     def __or__(self, other: Union[StrawberryType, type]) -> StrawberryType:\n         if other is None:\n             # Return the correct notation when using `StrawberryUnion | None`.\n-            return StrawberryOptional(of_type=self)\n+            return Optional[self]\n \n         # Raise an error in any other case.\n         # There is Work in progress to deal with more merging cases, see:\n", "issue": "TypeError: Forward references must evaluate to types.\nSo I am running Strawberry with Fastapi\r\n\r\n## Describe the Bug\r\n\r\nI have a schema like this:\r\n\r\n```\r\nfrom __future__ import annotations\r\nfrom enum import Enum\r\nimport strawberry\r\nimport datetime\r\nfrom strawberry.scalars import JSON\r\n\r\n@strawberry.enum\r\nclass Sex(Enum):\r\n    male = \"Male\"\r\n    female =\"Female\"\r\n\r\n@strawberry.type\r\nclass PersonBase:\r\n    name: JSON | None\r\n    sex: Sex | None\r\n\r\n@strawberry.type\r\nclass Client(PersonBase):\r\n    firm: Firm | None = None\r\n\r\n\r\n```\r\n When I try to run the server it throws back an error:\r\n\r\n```\r\n  File \"C:\\Users\\0\\Desktop\\Fastapi\\Test\\.\\app\\main.py\", line 14, in <module>\r\n    from app.schema import schema\r\n  File \"C:\\Users\\0\\Desktop\\Fastapi\\Test\\.\\app\\schema.py\", line 624, in <module>\r\n    schema = strawberry.Schema(query=Query, mutation = Mutation)\r\n  File \"C:\\Users\\0\\Envs\\Fastapi\\lib\\site-packages\\strawberry\\schema\\schema.py\", line 115, in __init__\r\n    self._schema = GraphQLSchema(\r\n  File \"C:\\Users\\0\\Envs\\Fastapi\\lib\\site-packages\\graphql\\type\\schema.py\", line 224, in __init__\r\n    collect_referenced_types(query)\r\n  File \"C:\\Users\\0\\Envs\\Fastapi\\lib\\site-packages\\graphql\\type\\schema.py\", line 433, in collect_referenced_types\r\n    collect_referenced_types(field.type)\r\n  File \"C:\\Users\\0\\Envs\\Fastapi\\lib\\site-packages\\graphql\\type\\schema.py\", line 433, in collect_referenced_types\r\n    collect_referenced_types(field.type)\r\n  File \"C:\\Users\\0\\Envs\\Fastapi\\lib\\site-packages\\graphql\\type\\schema.py\", line 432, in collect_referenced_types\r\n    for field in named_type.fields.values():\r\n  File \"C:\\Users\\0\\AppData\\Local\\Programs\\Python\\Python310\\lib\\functools.py\", line 970, in __get__\r\n    val = self.func(instance)\r\n  File \"C:\\Users\\0\\Envs\\Fastapi\\lib\\site-packages\\graphql\\type\\definition.py\", line 811, in fields\r\n    raise cls(f\"{self.name} fields cannot be resolved. {error}\") from error\r\nTypeError: Client fields cannot be resolved. Forward references must evaluate to types. Got <strawberry.type.StrawberryOptional object at 0x000002C85C5F5990>.\r\n```\r\nNote that if I change one thing like this making a required name field with a string the error is resolved\r\n\r\n```\r\n@strawberry.type\r\nclass Client(PersonBase):\r\n    firm: Firm | None = None\r\n    name: str | None\r\n```\r\n\r\nBut if I put PersonBase into the model like this, it still throws an error even though the name field is required as JSON.\r\n\r\n```\r\nclass Client:\r\n    firm: Firm | None = None\r\n    name: JSON | None\r\n    sex: Sex | None\r\n```\r\n\r\n\r\n## System Information\r\n\r\n - Operating system: Windows 10\r\n - Strawberry version (if applicable): strawberry-graphql==0.139.0\r\n\r\n## Additional Context\r\n\r\nNot sure if this is an bug or I did something wrong but I find this behavior strange because the JSON and Enum are both scalars but required and they triggered a type error.\r\n\n\n<!-- POLAR PLEDGE BADGE START -->\n## Upvote & Fund\n\n- We're using [Polar.sh](https://polar.sh/strawberry-graphql) so you can upvote and help fund this issue.\n- We receive the funding once the issue is completed & confirmed by you.\n- Thank you in advance for helping prioritize & fund our backlog.\n\n<a href=\"https://polar.sh/strawberry-graphql/strawberry/issues/2465\">\n<picture>\n  <source media=\"(prefers-color-scheme: dark)\" srcset=\"https://polar.sh/api/github/strawberry-graphql/strawberry/issues/2465/pledge.svg?darkmode=1\">\n  <img alt=\"Fund with Polar\" src=\"https://polar.sh/api/github/strawberry-graphql/strawberry/issues/2465/pledge.svg\">\n</picture>\n</a>\n<!-- POLAR PLEDGE BADGE END -->\n\n", "before_files": [{"content": "from __future__ import annotations\n\nimport sys\nfrom dataclasses import dataclass\nfrom typing import (\n    TYPE_CHECKING,\n    Any,\n    Callable,\n    Iterable,\n    Mapping,\n    NewType,\n    Optional,\n    Type,\n    TypeVar,\n    Union,\n    overload,\n)\n\nfrom strawberry.exceptions import InvalidUnionTypeError\nfrom strawberry.type import StrawberryOptional, StrawberryType\n\nfrom .utils.str_converters import to_camel_case\n\nif TYPE_CHECKING:\n    from graphql import GraphQLScalarType\n\n\n# in python 3.10+ NewType is a class\nif sys.version_info >= (3, 10):\n    _T = TypeVar(\"_T\", bound=Union[type, NewType])\nelse:\n    _T = TypeVar(\"_T\", bound=type)\n\n\ndef identity(x: _T) -> _T:\n    return x\n\n\n@dataclass\nclass ScalarDefinition(StrawberryType):\n    name: str\n    description: Optional[str]\n    specified_by_url: Optional[str]\n    serialize: Optional[Callable]\n    parse_value: Optional[Callable]\n    parse_literal: Optional[Callable]\n    directives: Iterable[object] = ()\n\n    # Optionally store the GraphQLScalarType instance so that we don't get\n    # duplicates\n    implementation: Optional[GraphQLScalarType] = None\n\n    # used for better error messages\n    _source_file: Optional[str] = None\n    _source_line: Optional[int] = None\n\n    def copy_with(\n        self, type_var_map: Mapping[TypeVar, Union[StrawberryType, type]]\n    ) -> Union[StrawberryType, type]:\n        return super().copy_with(type_var_map)  # type: ignore[safe-super]\n\n    @property\n    def is_generic(self) -> bool:\n        return False\n\n\nclass ScalarWrapper:\n    _scalar_definition: ScalarDefinition\n\n    def __init__(self, wrap: Callable[[Any], Any]):\n        self.wrap = wrap\n\n    def __call__(self, *args: str, **kwargs: Any):\n        return self.wrap(*args, **kwargs)\n\n    def __or__(self, other: Union[StrawberryType, type]) -> StrawberryType:\n        if other is None:\n            # Return the correct notation when using `StrawberryUnion | None`.\n            return StrawberryOptional(of_type=self)\n\n        # Raise an error in any other case.\n        # There is Work in progress to deal with more merging cases, see:\n        # https://github.com/strawberry-graphql/strawberry/pull/1455\n        raise InvalidUnionTypeError(str(other), self.wrap)\n\n\ndef _process_scalar(\n    cls: Type[_T],\n    *,\n    name: Optional[str] = None,\n    description: Optional[str] = None,\n    specified_by_url: Optional[str] = None,\n    serialize: Optional[Callable] = None,\n    parse_value: Optional[Callable] = None,\n    parse_literal: Optional[Callable] = None,\n    directives: Iterable[object] = (),\n):\n    from strawberry.exceptions.handler import should_use_rich_exceptions\n\n    name = name or to_camel_case(cls.__name__)\n\n    _source_file = None\n    _source_line = None\n\n    if should_use_rich_exceptions():\n        frame = sys._getframe(3)\n\n        _source_file = frame.f_code.co_filename\n        _source_line = frame.f_lineno\n\n    wrapper = ScalarWrapper(cls)\n    wrapper._scalar_definition = ScalarDefinition(\n        name=name,\n        description=description,\n        specified_by_url=specified_by_url,\n        serialize=serialize,\n        parse_literal=parse_literal,\n        parse_value=parse_value,\n        directives=directives,\n        _source_file=_source_file,\n        _source_line=_source_line,\n    )\n\n    return wrapper\n\n\n@overload\ndef scalar(\n    *,\n    name: Optional[str] = None,\n    description: Optional[str] = None,\n    specified_by_url: Optional[str] = None,\n    serialize: Callable = identity,\n    parse_value: Optional[Callable] = None,\n    parse_literal: Optional[Callable] = None,\n    directives: Iterable[object] = (),\n) -> Callable[[_T], _T]:\n    ...\n\n\n@overload\ndef scalar(\n    cls: _T,\n    *,\n    name: Optional[str] = None,\n    description: Optional[str] = None,\n    specified_by_url: Optional[str] = None,\n    serialize: Callable = identity,\n    parse_value: Optional[Callable] = None,\n    parse_literal: Optional[Callable] = None,\n    directives: Iterable[object] = (),\n) -> _T:\n    ...\n\n\n# FIXME: We are tricking pyright into thinking that we are returning the given type\n# here or else it won't let us use any custom scalar to annotate attributes in\n# dataclasses/types. This should be properly solved when implementing StrawberryScalar\ndef scalar(\n    cls=None,\n    *,\n    name: Optional[str] = None,\n    description: Optional[str] = None,\n    specified_by_url: Optional[str] = None,\n    serialize: Callable = identity,\n    parse_value: Optional[Callable] = None,\n    parse_literal: Optional[Callable] = None,\n    directives: Iterable[object] = (),\n) -> Any:\n    \"\"\"Annotates a class or type as a GraphQL custom scalar.\n\n    Example usages:\n\n    >>> strawberry.scalar(\n    >>>     datetime.date,\n    >>>     serialize=lambda value: value.isoformat(),\n    >>>     parse_value=datetime.parse_date\n    >>> )\n\n    >>> Base64Encoded = strawberry.scalar(\n    >>>     NewType(\"Base64Encoded\", bytes),\n    >>>     serialize=base64.b64encode,\n    >>>     parse_value=base64.b64decode\n    >>> )\n\n    >>> @strawberry.scalar(\n    >>>     serialize=lambda value: \",\".join(value.items),\n    >>>     parse_value=lambda value: CustomList(value.split(\",\"))\n    >>> )\n    >>> class CustomList:\n    >>>     def __init__(self, items):\n    >>>         self.items = items\n\n    \"\"\"\n\n    if parse_value is None:\n        parse_value = cls\n\n    def wrap(cls: Type):\n        return _process_scalar(\n            cls,\n            name=name,\n            description=description,\n            specified_by_url=specified_by_url,\n            serialize=serialize,\n            parse_value=parse_value,\n            parse_literal=parse_literal,\n            directives=directives,\n        )\n\n    if cls is None:\n        return wrap\n\n    return wrap(cls)\n", "path": "strawberry/custom_scalar.py"}], "after_files": [{"content": "from __future__ import annotations\n\nimport sys\nfrom dataclasses import dataclass\nfrom typing import (\n    TYPE_CHECKING,\n    Any,\n    Callable,\n    Iterable,\n    Mapping,\n    NewType,\n    Optional,\n    Type,\n    TypeVar,\n    Union,\n    overload,\n)\n\nfrom strawberry.exceptions import InvalidUnionTypeError\nfrom strawberry.type import StrawberryType\n\nfrom .utils.str_converters import to_camel_case\n\nif TYPE_CHECKING:\n    from graphql import GraphQLScalarType\n\n\n# in python 3.10+ NewType is a class\nif sys.version_info >= (3, 10):\n    _T = TypeVar(\"_T\", bound=Union[type, NewType])\nelse:\n    _T = TypeVar(\"_T\", bound=type)\n\n\ndef identity(x: _T) -> _T:\n    return x\n\n\n@dataclass\nclass ScalarDefinition(StrawberryType):\n    name: str\n    description: Optional[str]\n    specified_by_url: Optional[str]\n    serialize: Optional[Callable]\n    parse_value: Optional[Callable]\n    parse_literal: Optional[Callable]\n    directives: Iterable[object] = ()\n\n    # Optionally store the GraphQLScalarType instance so that we don't get\n    # duplicates\n    implementation: Optional[GraphQLScalarType] = None\n\n    # used for better error messages\n    _source_file: Optional[str] = None\n    _source_line: Optional[int] = None\n\n    def copy_with(\n        self, type_var_map: Mapping[TypeVar, Union[StrawberryType, type]]\n    ) -> Union[StrawberryType, type]:\n        return super().copy_with(type_var_map)  # type: ignore[safe-super]\n\n    @property\n    def is_generic(self) -> bool:\n        return False\n\n\nclass ScalarWrapper:\n    _scalar_definition: ScalarDefinition\n\n    def __init__(self, wrap: Callable[[Any], Any]):\n        self.wrap = wrap\n\n    def __call__(self, *args: str, **kwargs: Any):\n        return self.wrap(*args, **kwargs)\n\n    def __or__(self, other: Union[StrawberryType, type]) -> StrawberryType:\n        if other is None:\n            # Return the correct notation when using `StrawberryUnion | None`.\n            return Optional[self]\n\n        # Raise an error in any other case.\n        # There is Work in progress to deal with more merging cases, see:\n        # https://github.com/strawberry-graphql/strawberry/pull/1455\n        raise InvalidUnionTypeError(str(other), self.wrap)\n\n\ndef _process_scalar(\n    cls: Type[_T],\n    *,\n    name: Optional[str] = None,\n    description: Optional[str] = None,\n    specified_by_url: Optional[str] = None,\n    serialize: Optional[Callable] = None,\n    parse_value: Optional[Callable] = None,\n    parse_literal: Optional[Callable] = None,\n    directives: Iterable[object] = (),\n):\n    from strawberry.exceptions.handler import should_use_rich_exceptions\n\n    name = name or to_camel_case(cls.__name__)\n\n    _source_file = None\n    _source_line = None\n\n    if should_use_rich_exceptions():\n        frame = sys._getframe(3)\n\n        _source_file = frame.f_code.co_filename\n        _source_line = frame.f_lineno\n\n    wrapper = ScalarWrapper(cls)\n    wrapper._scalar_definition = ScalarDefinition(\n        name=name,\n        description=description,\n        specified_by_url=specified_by_url,\n        serialize=serialize,\n        parse_literal=parse_literal,\n        parse_value=parse_value,\n        directives=directives,\n        _source_file=_source_file,\n        _source_line=_source_line,\n    )\n\n    return wrapper\n\n\n@overload\ndef scalar(\n    *,\n    name: Optional[str] = None,\n    description: Optional[str] = None,\n    specified_by_url: Optional[str] = None,\n    serialize: Callable = identity,\n    parse_value: Optional[Callable] = None,\n    parse_literal: Optional[Callable] = None,\n    directives: Iterable[object] = (),\n) -> Callable[[_T], _T]:\n    ...\n\n\n@overload\ndef scalar(\n    cls: _T,\n    *,\n    name: Optional[str] = None,\n    description: Optional[str] = None,\n    specified_by_url: Optional[str] = None,\n    serialize: Callable = identity,\n    parse_value: Optional[Callable] = None,\n    parse_literal: Optional[Callable] = None,\n    directives: Iterable[object] = (),\n) -> _T:\n    ...\n\n\n# FIXME: We are tricking pyright into thinking that we are returning the given type\n# here or else it won't let us use any custom scalar to annotate attributes in\n# dataclasses/types. This should be properly solved when implementing StrawberryScalar\ndef scalar(\n    cls=None,\n    *,\n    name: Optional[str] = None,\n    description: Optional[str] = None,\n    specified_by_url: Optional[str] = None,\n    serialize: Callable = identity,\n    parse_value: Optional[Callable] = None,\n    parse_literal: Optional[Callable] = None,\n    directives: Iterable[object] = (),\n) -> Any:\n    \"\"\"Annotates a class or type as a GraphQL custom scalar.\n\n    Example usages:\n\n    >>> strawberry.scalar(\n    >>>     datetime.date,\n    >>>     serialize=lambda value: value.isoformat(),\n    >>>     parse_value=datetime.parse_date\n    >>> )\n\n    >>> Base64Encoded = strawberry.scalar(\n    >>>     NewType(\"Base64Encoded\", bytes),\n    >>>     serialize=base64.b64encode,\n    >>>     parse_value=base64.b64decode\n    >>> )\n\n    >>> @strawberry.scalar(\n    >>>     serialize=lambda value: \",\".join(value.items),\n    >>>     parse_value=lambda value: CustomList(value.split(\",\"))\n    >>> )\n    >>> class CustomList:\n    >>>     def __init__(self, items):\n    >>>         self.items = items\n\n    \"\"\"\n\n    if parse_value is None:\n        parse_value = cls\n\n    def wrap(cls: Type):\n        return _process_scalar(\n            cls,\n            name=name,\n            description=description,\n            specified_by_url=specified_by_url,\n            serialize=serialize,\n            parse_value=parse_value,\n            parse_literal=parse_literal,\n            directives=directives,\n        )\n\n    if cls is None:\n        return wrap\n\n    return wrap(cls)\n", "path": "strawberry/custom_scalar.py"}]}