We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Pydantic converted types have no way to deprecate fields
Since we recreate the field object for the values that use simple fields, there isn't a clean way to add a deprecation_reason to a field from a pydantic class. The same is true for permission_classes and directives.

--- 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/experimental/pydantic/object_type.py`
Content:
```
1 from __future__ import annotations
2 
3 import builtins
4 import dataclasses
5 import warnings
6 from functools import partial
7 from typing import (
8     TYPE_CHECKING,
9     Any,
10     Callable,
11     Dict,
12     List,
13     Optional,
14     Sequence,
15     Set,
16     Type,
17     cast,
18 )
19 
20 from pydantic import BaseModel
21 from pydantic.fields import ModelField
22 from typing_extensions import Literal
23 
24 from graphql import GraphQLResolveInfo
25 
26 import strawberry
27 from strawberry.arguments import UNSET
28 from strawberry.experimental.pydantic.conversion import (
29     convert_pydantic_model_to_strawberry_class,
30     convert_strawberry_class_to_pydantic_model,
31 )
32 from strawberry.experimental.pydantic.fields import get_basic_type
33 from strawberry.experimental.pydantic.utils import (
34     DataclassCreationFields,
35     ensure_all_auto_fields_in_pydantic,
36     get_default_factory_for_field,
37     get_private_fields,
38     sort_creation_fields,
39 )
40 from strawberry.field import StrawberryField
41 from strawberry.object_type import _process_type, _wrap_dataclass
42 from strawberry.schema_directive import StrawberrySchemaDirective
43 from strawberry.types.type_resolver import _get_fields
44 from strawberry.types.types import TypeDefinition
45 
46 from .exceptions import MissingFieldsListError, UnregisteredTypeException
47 
48 
49 def replace_pydantic_types(type_: Any, is_input: bool):
50     origin = getattr(type_, "__origin__", None)
51     if origin is Literal:
52         # Literal does not have types in its __args__ so we return early
53         return type_
54     if hasattr(type_, "__args__"):
55         replaced_type = type_.copy_with(
56             tuple(replace_pydantic_types(t, is_input) for t in type_.__args__)
57         )
58 
59         if isinstance(replaced_type, TypeDefinition):
60             # TODO: Not sure if this is necessary. No coverage in tests
61             # TODO: Unnecessary with StrawberryObject
62 
63             replaced_type = builtins.type(
64                 replaced_type.name,
65                 (),
66                 {"_type_definition": replaced_type},
67             )
68 
69         return replaced_type
70 
71     if issubclass(type_, BaseModel):
72         attr = "_strawberry_input_type" if is_input else "_strawberry_type"
73         if hasattr(type_, attr):
74             return getattr(type_, attr)
75         else:
76             raise UnregisteredTypeException(type_)
77 
78     return type_
79 
80 
81 def get_type_for_field(field: ModelField, is_input: bool):
82     outer_type = field.outer_type_
83     basic_type = get_basic_type(outer_type)
84     replaced_type = replace_pydantic_types(basic_type, is_input)
85 
86     if not field.required:
87         return Optional[replaced_type]
88     else:
89         return replaced_type
90 
91 
92 def _build_dataclass_creation_fields(
93     field: ModelField,
94     is_input: bool,
95     existing_fields: Dict[str, StrawberryField],
96     auto_fields_set: Set[str],
97     use_pydantic_alias: bool,
98 ) -> DataclassCreationFields:
99     type_annotation = (
100         get_type_for_field(field, is_input)
101         if field.name in auto_fields_set
102         else existing_fields[field.name].type
103     )
104 
105     if (
106         field.name in existing_fields
107         and existing_fields[field.name].base_resolver is not None
108     ):
109         # if the user has defined a resolver for this field, always use it
110         strawberry_field = existing_fields[field.name]
111     else:
112         # otherwise we build an appropriate strawberry field that resolves it
113         strawberry_field = StrawberryField(
114             python_name=field.name,
115             graphql_name=field.alias
116             if field.has_alias and use_pydantic_alias
117             else None,
118             # always unset because we use default_factory instead
119             default=UNSET,
120             default_factory=get_default_factory_for_field(field),
121             type_annotation=type_annotation,
122             description=field.field_info.description,
123         )
124 
125     return DataclassCreationFields(
126         name=field.name,
127         type_annotation=type_annotation,
128         field=strawberry_field,
129     )
130 
131 
132 if TYPE_CHECKING:
133     from strawberry.experimental.pydantic.conversion_types import (
134         PydanticModel,
135         StrawberryTypeFromPydantic,
136     )
137 
138 
139 def type(
140     model: Type[PydanticModel],
141     *,
142     fields: Optional[List[str]] = None,
143     name: Optional[str] = None,
144     is_input: bool = False,
145     is_interface: bool = False,
146     description: Optional[str] = None,
147     directives: Optional[Sequence[StrawberrySchemaDirective]] = (),
148     all_fields: bool = False,
149     use_pydantic_alias: bool = True,
150 ) -> Callable[..., Type[StrawberryTypeFromPydantic[PydanticModel]]]:
151     def wrap(cls: Any) -> Type[StrawberryTypeFromPydantic[PydanticModel]]:
152         model_fields = model.__fields__
153         original_fields_set = set(fields) if fields else set([])
154 
155         if fields:
156             warnings.warn(
157                 "`fields` is deprecated, use `auto` type annotations instead",
158                 DeprecationWarning,
159             )
160 
161         existing_fields = getattr(cls, "__annotations__", {})
162         # these are the fields that matched a field name in the pydantic model
163         # and should copy their alias from the pydantic model
164         fields_set = original_fields_set.union(
165             set(name for name, _ in existing_fields.items() if name in model_fields)
166         )
167         # these are the fields that were marked with strawberry.auto and
168         # should copy their type from the pydantic model
169         auto_fields_set = original_fields_set.union(
170             set(name for name, typ in existing_fields.items() if typ == strawberry.auto)
171         )
172 
173         if all_fields:
174             if fields_set:
175                 warnings.warn(
176                     "Using all_fields overrides any explicitly defined fields "
177                     "in the model, using both is likely a bug",
178                     stacklevel=2,
179                 )
180             fields_set = set(model_fields.keys())
181             auto_fields_set = set(model_fields.keys())
182 
183         if not fields_set:
184             raise MissingFieldsListError(cls)
185 
186         ensure_all_auto_fields_in_pydantic(
187             model=model, auto_fields=auto_fields_set, cls_name=cls.__name__
188         )
189 
190         wrapped = _wrap_dataclass(cls)
191         extra_strawberry_fields = _get_fields(wrapped)
192         extra_fields = cast(List[dataclasses.Field], extra_strawberry_fields)
193         private_fields = get_private_fields(wrapped)
194 
195         extra_fields_dict = {field.name: field for field in extra_strawberry_fields}
196 
197         all_model_fields: List[DataclassCreationFields] = [
198             _build_dataclass_creation_fields(
199                 field, is_input, extra_fields_dict, auto_fields_set, use_pydantic_alias
200             )
201             for field_name, field in model_fields.items()
202             if field_name in fields_set
203         ]
204 
205         all_model_fields.extend(
206             (
207                 DataclassCreationFields(
208                     name=field.name,
209                     type_annotation=field.type,
210                     field=field,
211                 )
212                 for field in extra_fields + private_fields
213                 if field.name not in fields_set
214             )
215         )
216 
217         # Sort fields so that fields with missing defaults go first
218         sorted_fields = sort_creation_fields(all_model_fields)
219 
220         # Implicitly define `is_type_of` to support interfaces/unions that use
221         # pydantic objects (not the corresponding strawberry type)
222         @classmethod  # type: ignore
223         def is_type_of(cls: Type, obj: Any, _info: GraphQLResolveInfo) -> bool:
224             return isinstance(obj, (cls, model))
225 
226         namespace = {"is_type_of": is_type_of}
227         # We need to tell the difference between a from_pydantic method that is
228         # inherited from a base class and one that is defined by the user in the
229         # decorated class. We want to override the method only if it is
230         # inherited. To tell the difference, we compare the class name to the
231         # fully qualified name of the method, which will end in <class>.from_pydantic
232         has_custom_from_pydantic = hasattr(
233             cls, "from_pydantic"
234         ) and cls.from_pydantic.__qualname__.endswith(f"{cls.__name__}.from_pydantic")
235         has_custom_to_pydantic = hasattr(
236             cls, "to_pydantic"
237         ) and cls.to_pydantic.__qualname__.endswith(f"{cls.__name__}.to_pydantic")
238 
239         if has_custom_from_pydantic:
240             namespace["from_pydantic"] = cls.from_pydantic
241         if has_custom_to_pydantic:
242             namespace["to_pydantic"] = cls.to_pydantic
243 
244         cls = dataclasses.make_dataclass(
245             cls.__name__,
246             [field.to_tuple() for field in sorted_fields],
247             bases=cls.__bases__,
248             namespace=namespace,
249         )
250 
251         _process_type(
252             cls,
253             name=name,
254             is_input=is_input,
255             is_interface=is_interface,
256             description=description,
257             directives=directives,
258         )
259 
260         if is_input:
261             model._strawberry_input_type = cls  # type: ignore
262         else:
263             model._strawberry_type = cls  # type: ignore
264         cls._pydantic_type = model
265 
266         def from_pydantic_default(
267             instance: PydanticModel, extra: Dict[str, Any] = None
268         ) -> StrawberryTypeFromPydantic[PydanticModel]:
269             return convert_pydantic_model_to_strawberry_class(
270                 cls=cls, model_instance=instance, extra=extra
271             )
272 
273         def to_pydantic_default(self) -> PydanticModel:
274             instance_kwargs = {
275                 f.name: convert_strawberry_class_to_pydantic_model(
276                     getattr(self, f.name)
277                 )
278                 for f in dataclasses.fields(self)
279             }
280             return model(**instance_kwargs)
281 
282         if not has_custom_from_pydantic:
283             cls.from_pydantic = staticmethod(from_pydantic_default)
284         if not has_custom_to_pydantic:
285             cls.to_pydantic = to_pydantic_default
286 
287         return cls
288 
289     return wrap
290 
291 
292 input = partial(type, is_input=True)
293 
294 interface = partial(type, is_interface=True)
295
```
--- 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/experimental/pydantic/object_type.py b/strawberry/experimental/pydantic/object_type.py
--- a/strawberry/experimental/pydantic/object_type.py
+++ b/strawberry/experimental/pydantic/object_type.py
@@ -110,6 +110,7 @@
         strawberry_field = existing_fields[field.name]
     else:
         # otherwise we build an appropriate strawberry field that resolves it
+        existing_field = existing_fields.get(field.name)
         strawberry_field = StrawberryField(
             python_name=field.name,
             graphql_name=field.alias
@@ -120,6 +121,13 @@
             default_factory=get_default_factory_for_field(field),
             type_annotation=type_annotation,
             description=field.field_info.description,
+            deprecation_reason=(
+                existing_field.deprecation_reason if existing_field else None
+            ),
+            permission_classes=(
+                existing_field.permission_classes if existing_field else []
+            ),
+            directives=existing_field.directives if existing_field else (),
         )
 
     return DataclassCreationFields(

{"golden_diff": "diff --git a/strawberry/experimental/pydantic/object_type.py b/strawberry/experimental/pydantic/object_type.py\n--- a/strawberry/experimental/pydantic/object_type.py\n+++ b/strawberry/experimental/pydantic/object_type.py\n@@ -110,6 +110,7 @@\n         strawberry_field = existing_fields[field.name]\n     else:\n         # otherwise we build an appropriate strawberry field that resolves it\n+        existing_field = existing_fields.get(field.name)\n         strawberry_field = StrawberryField(\n             python_name=field.name,\n             graphql_name=field.alias\n@@ -120,6 +121,13 @@\n             default_factory=get_default_factory_for_field(field),\n             type_annotation=type_annotation,\n             description=field.field_info.description,\n+            deprecation_reason=(\n+                existing_field.deprecation_reason if existing_field else None\n+            ),\n+            permission_classes=(\n+                existing_field.permission_classes if existing_field else []\n+            ),\n+            directives=existing_field.directives if existing_field else (),\n         )\n \n     return DataclassCreationFields(\n", "issue": "Pydantic converted types have no way to deprecate fields\nSince we recreate the field object for the values that use simple fields, there isn't a clean way to add a deprecation_reason to a field from a pydantic class. The same is true for permission_classes and directives.\n", "before_files": [{"content": "from __future__ import annotations\n\nimport builtins\nimport dataclasses\nimport warnings\nfrom functools import partial\nfrom typing import (\n    TYPE_CHECKING,\n    Any,\n    Callable,\n    Dict,\n    List,\n    Optional,\n    Sequence,\n    Set,\n    Type,\n    cast,\n)\n\nfrom pydantic import BaseModel\nfrom pydantic.fields import ModelField\nfrom typing_extensions import Literal\n\nfrom graphql import GraphQLResolveInfo\n\nimport strawberry\nfrom strawberry.arguments import UNSET\nfrom strawberry.experimental.pydantic.conversion import (\n    convert_pydantic_model_to_strawberry_class,\n    convert_strawberry_class_to_pydantic_model,\n)\nfrom strawberry.experimental.pydantic.fields import get_basic_type\nfrom strawberry.experimental.pydantic.utils import (\n    DataclassCreationFields,\n    ensure_all_auto_fields_in_pydantic,\n    get_default_factory_for_field,\n    get_private_fields,\n    sort_creation_fields,\n)\nfrom strawberry.field import StrawberryField\nfrom strawberry.object_type import _process_type, _wrap_dataclass\nfrom strawberry.schema_directive import StrawberrySchemaDirective\nfrom strawberry.types.type_resolver import _get_fields\nfrom strawberry.types.types import TypeDefinition\n\nfrom .exceptions import MissingFieldsListError, UnregisteredTypeException\n\n\ndef replace_pydantic_types(type_: Any, is_input: bool):\n    origin = getattr(type_, \"__origin__\", None)\n    if origin is Literal:\n        # Literal does not have types in its __args__ so we return early\n        return type_\n    if hasattr(type_, \"__args__\"):\n        replaced_type = type_.copy_with(\n            tuple(replace_pydantic_types(t, is_input) for t in type_.__args__)\n        )\n\n        if isinstance(replaced_type, TypeDefinition):\n            # TODO: Not sure if this is necessary. No coverage in tests\n            # TODO: Unnecessary with StrawberryObject\n\n            replaced_type = builtins.type(\n                replaced_type.name,\n                (),\n                {\"_type_definition\": replaced_type},\n            )\n\n        return replaced_type\n\n    if issubclass(type_, BaseModel):\n        attr = \"_strawberry_input_type\" if is_input else \"_strawberry_type\"\n        if hasattr(type_, attr):\n            return getattr(type_, attr)\n        else:\n            raise UnregisteredTypeException(type_)\n\n    return type_\n\n\ndef get_type_for_field(field: ModelField, is_input: bool):\n    outer_type = field.outer_type_\n    basic_type = get_basic_type(outer_type)\n    replaced_type = replace_pydantic_types(basic_type, is_input)\n\n    if not field.required:\n        return Optional[replaced_type]\n    else:\n        return replaced_type\n\n\ndef _build_dataclass_creation_fields(\n    field: ModelField,\n    is_input: bool,\n    existing_fields: Dict[str, StrawberryField],\n    auto_fields_set: Set[str],\n    use_pydantic_alias: bool,\n) -> DataclassCreationFields:\n    type_annotation = (\n        get_type_for_field(field, is_input)\n        if field.name in auto_fields_set\n        else existing_fields[field.name].type\n    )\n\n    if (\n        field.name in existing_fields\n        and existing_fields[field.name].base_resolver is not None\n    ):\n        # if the user has defined a resolver for this field, always use it\n        strawberry_field = existing_fields[field.name]\n    else:\n        # otherwise we build an appropriate strawberry field that resolves it\n        strawberry_field = StrawberryField(\n            python_name=field.name,\n            graphql_name=field.alias\n            if field.has_alias and use_pydantic_alias\n            else None,\n            # always unset because we use default_factory instead\n            default=UNSET,\n            default_factory=get_default_factory_for_field(field),\n            type_annotation=type_annotation,\n            description=field.field_info.description,\n        )\n\n    return DataclassCreationFields(\n        name=field.name,\n        type_annotation=type_annotation,\n        field=strawberry_field,\n    )\n\n\nif TYPE_CHECKING:\n    from strawberry.experimental.pydantic.conversion_types import (\n        PydanticModel,\n        StrawberryTypeFromPydantic,\n    )\n\n\ndef type(\n    model: Type[PydanticModel],\n    *,\n    fields: Optional[List[str]] = None,\n    name: Optional[str] = None,\n    is_input: bool = False,\n    is_interface: bool = False,\n    description: Optional[str] = None,\n    directives: Optional[Sequence[StrawberrySchemaDirective]] = (),\n    all_fields: bool = False,\n    use_pydantic_alias: bool = True,\n) -> Callable[..., Type[StrawberryTypeFromPydantic[PydanticModel]]]:\n    def wrap(cls: Any) -> Type[StrawberryTypeFromPydantic[PydanticModel]]:\n        model_fields = model.__fields__\n        original_fields_set = set(fields) if fields else set([])\n\n        if fields:\n            warnings.warn(\n                \"`fields` is deprecated, use `auto` type annotations instead\",\n                DeprecationWarning,\n            )\n\n        existing_fields = getattr(cls, \"__annotations__\", {})\n        # these are the fields that matched a field name in the pydantic model\n        # and should copy their alias from the pydantic model\n        fields_set = original_fields_set.union(\n            set(name for name, _ in existing_fields.items() if name in model_fields)\n        )\n        # these are the fields that were marked with strawberry.auto and\n        # should copy their type from the pydantic model\n        auto_fields_set = original_fields_set.union(\n            set(name for name, typ in existing_fields.items() if typ == strawberry.auto)\n        )\n\n        if all_fields:\n            if fields_set:\n                warnings.warn(\n                    \"Using all_fields overrides any explicitly defined fields \"\n                    \"in the model, using both is likely a bug\",\n                    stacklevel=2,\n                )\n            fields_set = set(model_fields.keys())\n            auto_fields_set = set(model_fields.keys())\n\n        if not fields_set:\n            raise MissingFieldsListError(cls)\n\n        ensure_all_auto_fields_in_pydantic(\n            model=model, auto_fields=auto_fields_set, cls_name=cls.__name__\n        )\n\n        wrapped = _wrap_dataclass(cls)\n        extra_strawberry_fields = _get_fields(wrapped)\n        extra_fields = cast(List[dataclasses.Field], extra_strawberry_fields)\n        private_fields = get_private_fields(wrapped)\n\n        extra_fields_dict = {field.name: field for field in extra_strawberry_fields}\n\n        all_model_fields: List[DataclassCreationFields] = [\n            _build_dataclass_creation_fields(\n                field, is_input, extra_fields_dict, auto_fields_set, use_pydantic_alias\n            )\n            for field_name, field in model_fields.items()\n            if field_name in fields_set\n        ]\n\n        all_model_fields.extend(\n            (\n                DataclassCreationFields(\n                    name=field.name,\n                    type_annotation=field.type,\n                    field=field,\n                )\n                for field in extra_fields + private_fields\n                if field.name not in fields_set\n            )\n        )\n\n        # Sort fields so that fields with missing defaults go first\n        sorted_fields = sort_creation_fields(all_model_fields)\n\n        # Implicitly define `is_type_of` to support interfaces/unions that use\n        # pydantic objects (not the corresponding strawberry type)\n        @classmethod  # type: ignore\n        def is_type_of(cls: Type, obj: Any, _info: GraphQLResolveInfo) -> bool:\n            return isinstance(obj, (cls, model))\n\n        namespace = {\"is_type_of\": is_type_of}\n        # We need to tell the difference between a from_pydantic method that is\n        # inherited from a base class and one that is defined by the user in the\n        # decorated class. We want to override the method only if it is\n        # inherited. To tell the difference, we compare the class name to the\n        # fully qualified name of the method, which will end in <class>.from_pydantic\n        has_custom_from_pydantic = hasattr(\n            cls, \"from_pydantic\"\n        ) and cls.from_pydantic.__qualname__.endswith(f\"{cls.__name__}.from_pydantic\")\n        has_custom_to_pydantic = hasattr(\n            cls, \"to_pydantic\"\n        ) and cls.to_pydantic.__qualname__.endswith(f\"{cls.__name__}.to_pydantic\")\n\n        if has_custom_from_pydantic:\n            namespace[\"from_pydantic\"] = cls.from_pydantic\n        if has_custom_to_pydantic:\n            namespace[\"to_pydantic\"] = cls.to_pydantic\n\n        cls = dataclasses.make_dataclass(\n            cls.__name__,\n            [field.to_tuple() for field in sorted_fields],\n            bases=cls.__bases__,\n            namespace=namespace,\n        )\n\n        _process_type(\n            cls,\n            name=name,\n            is_input=is_input,\n            is_interface=is_interface,\n            description=description,\n            directives=directives,\n        )\n\n        if is_input:\n            model._strawberry_input_type = cls  # type: ignore\n        else:\n            model._strawberry_type = cls  # type: ignore\n        cls._pydantic_type = model\n\n        def from_pydantic_default(\n            instance: PydanticModel, extra: Dict[str, Any] = None\n        ) -> StrawberryTypeFromPydantic[PydanticModel]:\n            return convert_pydantic_model_to_strawberry_class(\n                cls=cls, model_instance=instance, extra=extra\n            )\n\n        def to_pydantic_default(self) -> PydanticModel:\n            instance_kwargs = {\n                f.name: convert_strawberry_class_to_pydantic_model(\n                    getattr(self, f.name)\n                )\n                for f in dataclasses.fields(self)\n            }\n            return model(**instance_kwargs)\n\n        if not has_custom_from_pydantic:\n            cls.from_pydantic = staticmethod(from_pydantic_default)\n        if not has_custom_to_pydantic:\n            cls.to_pydantic = to_pydantic_default\n\n        return cls\n\n    return wrap\n\n\ninput = partial(type, is_input=True)\n\ninterface = partial(type, is_interface=True)\n", "path": "strawberry/experimental/pydantic/object_type.py"}], "after_files": [{"content": "from __future__ import annotations\n\nimport builtins\nimport dataclasses\nimport warnings\nfrom functools import partial\nfrom typing import (\n    TYPE_CHECKING,\n    Any,\n    Callable,\n    Dict,\n    List,\n    Optional,\n    Sequence,\n    Set,\n    Type,\n    cast,\n)\n\nfrom pydantic import BaseModel\nfrom pydantic.fields import ModelField\nfrom typing_extensions import Literal\n\nfrom graphql import GraphQLResolveInfo\n\nimport strawberry\nfrom strawberry.arguments import UNSET\nfrom strawberry.experimental.pydantic.conversion import (\n    convert_pydantic_model_to_strawberry_class,\n    convert_strawberry_class_to_pydantic_model,\n)\nfrom strawberry.experimental.pydantic.fields import get_basic_type\nfrom strawberry.experimental.pydantic.utils import (\n    DataclassCreationFields,\n    ensure_all_auto_fields_in_pydantic,\n    get_default_factory_for_field,\n    get_private_fields,\n    sort_creation_fields,\n)\nfrom strawberry.field import StrawberryField\nfrom strawberry.object_type import _process_type, _wrap_dataclass\nfrom strawberry.schema_directive import StrawberrySchemaDirective\nfrom strawberry.types.type_resolver import _get_fields\nfrom strawberry.types.types import TypeDefinition\n\nfrom .exceptions import MissingFieldsListError, UnregisteredTypeException\n\n\ndef replace_pydantic_types(type_: Any, is_input: bool):\n    origin = getattr(type_, \"__origin__\", None)\n    if origin is Literal:\n        # Literal does not have types in its __args__ so we return early\n        return type_\n    if hasattr(type_, \"__args__\"):\n        replaced_type = type_.copy_with(\n            tuple(replace_pydantic_types(t, is_input) for t in type_.__args__)\n        )\n\n        if isinstance(replaced_type, TypeDefinition):\n            # TODO: Not sure if this is necessary. No coverage in tests\n            # TODO: Unnecessary with StrawberryObject\n\n            replaced_type = builtins.type(\n                replaced_type.name,\n                (),\n                {\"_type_definition\": replaced_type},\n            )\n\n        return replaced_type\n\n    if issubclass(type_, BaseModel):\n        attr = \"_strawberry_input_type\" if is_input else \"_strawberry_type\"\n        if hasattr(type_, attr):\n            return getattr(type_, attr)\n        else:\n            raise UnregisteredTypeException(type_)\n\n    return type_\n\n\ndef get_type_for_field(field: ModelField, is_input: bool):\n    outer_type = field.outer_type_\n    basic_type = get_basic_type(outer_type)\n    replaced_type = replace_pydantic_types(basic_type, is_input)\n\n    if not field.required:\n        return Optional[replaced_type]\n    else:\n        return replaced_type\n\n\ndef _build_dataclass_creation_fields(\n    field: ModelField,\n    is_input: bool,\n    existing_fields: Dict[str, StrawberryField],\n    auto_fields_set: Set[str],\n    use_pydantic_alias: bool,\n) -> DataclassCreationFields:\n    type_annotation = (\n        get_type_for_field(field, is_input)\n        if field.name in auto_fields_set\n        else existing_fields[field.name].type\n    )\n\n    if (\n        field.name in existing_fields\n        and existing_fields[field.name].base_resolver is not None\n    ):\n        # if the user has defined a resolver for this field, always use it\n        strawberry_field = existing_fields[field.name]\n    else:\n        # otherwise we build an appropriate strawberry field that resolves it\n        existing_field = existing_fields.get(field.name)\n        strawberry_field = StrawberryField(\n            python_name=field.name,\n            graphql_name=field.alias\n            if field.has_alias and use_pydantic_alias\n            else None,\n            # always unset because we use default_factory instead\n            default=UNSET,\n            default_factory=get_default_factory_for_field(field),\n            type_annotation=type_annotation,\n            description=field.field_info.description,\n            deprecation_reason=(\n                existing_field.deprecation_reason if existing_field else None\n            ),\n            permission_classes=(\n                existing_field.permission_classes if existing_field else []\n            ),\n            directives=existing_field.directives if existing_field else (),\n        )\n\n    return DataclassCreationFields(\n        name=field.name,\n        type_annotation=type_annotation,\n        field=strawberry_field,\n    )\n\n\nif TYPE_CHECKING:\n    from strawberry.experimental.pydantic.conversion_types import (\n        PydanticModel,\n        StrawberryTypeFromPydantic,\n    )\n\n\ndef type(\n    model: Type[PydanticModel],\n    *,\n    fields: Optional[List[str]] = None,\n    name: Optional[str] = None,\n    is_input: bool = False,\n    is_interface: bool = False,\n    description: Optional[str] = None,\n    directives: Optional[Sequence[StrawberrySchemaDirective]] = (),\n    all_fields: bool = False,\n    use_pydantic_alias: bool = True,\n) -> Callable[..., Type[StrawberryTypeFromPydantic[PydanticModel]]]:\n    def wrap(cls: Any) -> Type[StrawberryTypeFromPydantic[PydanticModel]]:\n        model_fields = model.__fields__\n        original_fields_set = set(fields) if fields else set([])\n\n        if fields:\n            warnings.warn(\n                \"`fields` is deprecated, use `auto` type annotations instead\",\n                DeprecationWarning,\n            )\n\n        existing_fields = getattr(cls, \"__annotations__\", {})\n        # these are the fields that matched a field name in the pydantic model\n        # and should copy their alias from the pydantic model\n        fields_set = original_fields_set.union(\n            set(name for name, _ in existing_fields.items() if name in model_fields)\n        )\n        # these are the fields that were marked with strawberry.auto and\n        # should copy their type from the pydantic model\n        auto_fields_set = original_fields_set.union(\n            set(name for name, typ in existing_fields.items() if typ == strawberry.auto)\n        )\n\n        if all_fields:\n            if fields_set:\n                warnings.warn(\n                    \"Using all_fields overrides any explicitly defined fields \"\n                    \"in the model, using both is likely a bug\",\n                    stacklevel=2,\n                )\n            fields_set = set(model_fields.keys())\n            auto_fields_set = set(model_fields.keys())\n\n        if not fields_set:\n            raise MissingFieldsListError(cls)\n\n        ensure_all_auto_fields_in_pydantic(\n            model=model, auto_fields=auto_fields_set, cls_name=cls.__name__\n        )\n\n        wrapped = _wrap_dataclass(cls)\n        extra_strawberry_fields = _get_fields(wrapped)\n        extra_fields = cast(List[dataclasses.Field], extra_strawberry_fields)\n        private_fields = get_private_fields(wrapped)\n\n        extra_fields_dict = {field.name: field for field in extra_strawberry_fields}\n\n        all_model_fields: List[DataclassCreationFields] = [\n            _build_dataclass_creation_fields(\n                field, is_input, extra_fields_dict, auto_fields_set, use_pydantic_alias\n            )\n            for field_name, field in model_fields.items()\n            if field_name in fields_set\n        ]\n\n        all_model_fields.extend(\n            (\n                DataclassCreationFields(\n                    name=field.name,\n                    type_annotation=field.type,\n                    field=field,\n                )\n                for field in extra_fields + private_fields\n                if field.name not in fields_set\n            )\n        )\n\n        # Sort fields so that fields with missing defaults go first\n        sorted_fields = sort_creation_fields(all_model_fields)\n\n        # Implicitly define `is_type_of` to support interfaces/unions that use\n        # pydantic objects (not the corresponding strawberry type)\n        @classmethod  # type: ignore\n        def is_type_of(cls: Type, obj: Any, _info: GraphQLResolveInfo) -> bool:\n            return isinstance(obj, (cls, model))\n\n        namespace = {\"is_type_of\": is_type_of}\n        # We need to tell the difference between a from_pydantic method that is\n        # inherited from a base class and one that is defined by the user in the\n        # decorated class. We want to override the method only if it is\n        # inherited. To tell the difference, we compare the class name to the\n        # fully qualified name of the method, which will end in <class>.from_pydantic\n        has_custom_from_pydantic = hasattr(\n            cls, \"from_pydantic\"\n        ) and cls.from_pydantic.__qualname__.endswith(f\"{cls.__name__}.from_pydantic\")\n        has_custom_to_pydantic = hasattr(\n            cls, \"to_pydantic\"\n        ) and cls.to_pydantic.__qualname__.endswith(f\"{cls.__name__}.to_pydantic\")\n\n        if has_custom_from_pydantic:\n            namespace[\"from_pydantic\"] = cls.from_pydantic\n        if has_custom_to_pydantic:\n            namespace[\"to_pydantic\"] = cls.to_pydantic\n\n        cls = dataclasses.make_dataclass(\n            cls.__name__,\n            [field.to_tuple() for field in sorted_fields],\n            bases=cls.__bases__,\n            namespace=namespace,\n        )\n\n        _process_type(\n            cls,\n            name=name,\n            is_input=is_input,\n            is_interface=is_interface,\n            description=description,\n            directives=directives,\n        )\n\n        if is_input:\n            model._strawberry_input_type = cls  # type: ignore\n        else:\n            model._strawberry_type = cls  # type: ignore\n        cls._pydantic_type = model\n\n        def from_pydantic_default(\n            instance: PydanticModel, extra: Dict[str, Any] = None\n        ) -> StrawberryTypeFromPydantic[PydanticModel]:\n            return convert_pydantic_model_to_strawberry_class(\n                cls=cls, model_instance=instance, extra=extra\n            )\n\n        def to_pydantic_default(self) -> PydanticModel:\n            instance_kwargs = {\n                f.name: convert_strawberry_class_to_pydantic_model(\n                    getattr(self, f.name)\n                )\n                for f in dataclasses.fields(self)\n            }\n            return model(**instance_kwargs)\n\n        if not has_custom_from_pydantic:\n            cls.from_pydantic = staticmethod(from_pydantic_default)\n        if not has_custom_to_pydantic:\n            cls.to_pydantic = to_pydantic_default\n\n        return cls\n\n    return wrap\n\n\ninput = partial(type, is_input=True)\n\ninterface = partial(type, is_interface=True)\n", "path": "strawberry/experimental/pydantic/object_type.py"}]}