prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Type resolver not called when extending from pydantic model
  I have 2 types, Category and Articles, and I want the Category type to return its related Articles(I have tried with other simpler types too), but when defining a resolver in the Category type its not being called:
  
  ```python
  def articles_helper(root):  
      return []      #  <-whatever I return here, it always shows null
     
     
  @strawberry.experimental.pydantic.type(
      model=Category,
      fields=[
          'title',
          'description',
          'content',
          'template',
          'slug',
          'date_published',
          'date_updated',
      ])
  class CategoryType(Category):
      id: int
      articles: Optional[List[ArticleType]] = strawberry.field(resolver=articles_helper)  # <- resolver not called
  ```    
  
  Query type:
  ```python
  @strawberry.type()
  class Query:
      category: Optional[CategoryType] = field(resolver=get_category)  # this resolver is OK
  ```
  
  Always returns `null`:
  ```
  Query:
  
  {
    category(categoryId: 1) {
      id
      title
      articles {
        title
      }
    }
  }
  
  Response:
  
  {
    "data": {
      "category": {
        "id": 1,
        "title": "test",
        "articles": null      <- always
      }
    }
  }
  ```
  
  **I works when I don't extend from a pydantic model**
  
  --- 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 import builtins
  2 import dataclasses
  3 from functools import partial
  4 from typing import Any, Dict, List, Optional, Type
  5 
  6 from pydantic import BaseModel
  7 from pydantic.fields import ModelField
  8 
  9 from strawberry.arguments import UNSET
  10 from strawberry.experimental.pydantic.conversion import (
  11     convert_pydantic_model_to_strawberry_class,
  12 )
  13 from strawberry.experimental.pydantic.fields import get_basic_type
  14 from strawberry.field import StrawberryField
  15 from strawberry.object_type import _process_type
  16 from strawberry.types.types import FederationTypeParams, TypeDefinition
  17 
  18 from .exceptions import MissingFieldsListError, UnregisteredTypeException
  19 
  20 
  21 def replace_pydantic_types(type_: Any):
  22     if hasattr(type_, "__args__"):
  23         new_type = type_.copy_with(
  24             tuple(replace_pydantic_types(t) for t in type_.__args__)
  25         )
  26 
  27         if isinstance(new_type, TypeDefinition):
  28             # TODO: Not sure if this is necessary. No coverage in tests
  29             # TODO: Unnecessary with StrawberryObject
  30 
  31             new_type = builtins.type(
  32                 new_type.name,
  33                 (),
  34                 {"_type_definition": new_type},
  35             )
  36 
  37         return new_type
  38 
  39     if issubclass(type_, BaseModel):
  40         if hasattr(type_, "_strawberry_type"):
  41             return type_._strawberry_type
  42         else:
  43             raise UnregisteredTypeException(type_)
  44 
  45     return type_
  46 
  47 
  48 def get_type_for_field(field: ModelField):
  49     type_ = field.outer_type_
  50     type_ = get_basic_type(type_)
  51     type_ = replace_pydantic_types(type_)
  52 
  53     if not field.required:
  54         type_ = Optional[type_]
  55 
  56     return type_
  57 
  58 
  59 def type(
  60     model: Type[BaseModel],
  61     *,
  62     fields: List[str],
  63     name: Optional[str] = None,
  64     is_input: bool = False,
  65     is_interface: bool = False,
  66     description: Optional[str] = None,
  67     federation: Optional[FederationTypeParams] = None,
  68 ):
  69     def wrap(cls):
  70         if not fields:
  71             raise MissingFieldsListError(model)
  72 
  73         model_fields = model.__fields__
  74         fields_set = set(fields)
  75 
  76         all_fields = [
  77             (
  78                 name,
  79                 get_type_for_field(field),
  80                 StrawberryField(
  81                     python_name=field.name,
  82                     graphql_name=field.alias if field.has_alias else None,
  83                     default=field.default if not field.required else UNSET,
  84                     default_factory=(
  85                         field.default_factory if field.default_factory else UNSET
  86                     ),
  87                     type_annotation=get_type_for_field(field),
  88                 ),
  89             )
  90             for name, field in model_fields.items()
  91             if name in fields_set
  92         ]
  93 
  94         cls_annotations = getattr(cls, "__annotations__", {})
  95         all_fields.extend(
  96             (
  97                 (
  98                     name,
  99                     type_,
  100                     StrawberryField(
  101                         python_name=name,
  102                         graphql_name=None,
  103                         type_annotation=type_,
  104                         # we need a default value when adding additional fields
  105                         # on top of a type generated from Pydantic, this is because
  106                         # Pydantic Optional fields always have None as default value
  107                         # which breaks dataclasses generation; as we can't define
  108                         # a field without a default value after one with a default value
  109                         # adding fields at the beginning won't work as we will also
  110                         # support default values on them (so the problem will be just
  111                         # shifted around)
  112                         default=None,
  113                     ),
  114                 )
  115                 for name, type_ in cls_annotations.items()
  116             )
  117         )
  118 
  119         cls = dataclasses.make_dataclass(
  120             cls.__name__,
  121             all_fields,
  122         )
  123 
  124         _process_type(
  125             cls,
  126             name=name,
  127             is_input=is_input,
  128             is_interface=is_interface,
  129             description=description,
  130             federation=federation,
  131         )
  132 
  133         model._strawberry_type = cls  # type: ignore
  134 
  135         def from_pydantic(instance: Any, extra: Dict[str, Any] = None) -> Any:
  136             return convert_pydantic_model_to_strawberry_class(
  137                 cls=cls, model_instance=instance, extra=extra
  138             )
  139 
  140         def to_pydantic(self) -> Any:
  141             instance_kwargs = dataclasses.asdict(self)
  142 
  143             return model(**instance_kwargs)
  144 
  145         cls.from_pydantic = staticmethod(from_pydantic)
  146         cls.to_pydantic = to_pydantic
  147 
  148         return cls
  149 
  150     return wrap
  151 
  152 
  153 input = partial(type, is_input=True)
  154
  ```
  --- 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()
  
  ```
  
golden_diff: 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
  @@ -12,7 +12,8 @@
   )
   from strawberry.experimental.pydantic.fields import get_basic_type
   from strawberry.field import StrawberryField
  -from strawberry.object_type import _process_type
  +from strawberry.object_type import _process_type, _wrap_dataclass
  +from strawberry.types.type_resolver import _get_fields
   from strawberry.types.types import FederationTypeParams, TypeDefinition
   
   from .exceptions import MissingFieldsListError, UnregisteredTypeException
  @@ -91,34 +92,36 @@
               if name in fields_set
           ]
   
  -        cls_annotations = getattr(cls, "__annotations__", {})
  +        wrapped = _wrap_dataclass(cls)
  +        extra_fields = _get_fields(wrapped)
  +
           all_fields.extend(
               (
                   (
  -                    name,
  -                    type_,
  -                    StrawberryField(
  -                        python_name=name,
  -                        graphql_name=None,
  -                        type_annotation=type_,
  -                        # we need a default value when adding additional fields
  -                        # on top of a type generated from Pydantic, this is because
  -                        # Pydantic Optional fields always have None as default value
  -                        # which breaks dataclasses generation; as we can't define
  -                        # a field without a default value after one with a default value
  -                        # adding fields at the beginning won't work as we will also
  -                        # support default values on them (so the problem will be just
  -                        # shifted around)
  -                        default=None,
  -                    ),
  +                    field.name,
  +                    field.type,
  +                    field,
                   )
  -                for name, type_ in cls_annotations.items()
  +                for field in extra_fields
               )
           )
   
  +        # Sort fields so that fields with missing defaults go first
  +        # because dataclasses require that fields with no defaults are defined
  +        # first
  +        missing_default = []
  +        has_default = []
  +        for field in all_fields:
  +            if field[2].default is dataclasses.MISSING:
  +                missing_default.append(field)
  +            else:
  +                has_default.append(field)
  +
  +        sorted_fields = missing_default + has_default
  +
           cls = dataclasses.make_dataclass(
               cls.__name__,
  -            all_fields,
  +            sorted_fields,
           )
   
           _process_type(
  
verification_info: {"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@@ -12,7 +12,8 @@\n )\n from strawberry.experimental.pydantic.fields import get_basic_type\n from strawberry.field import StrawberryField\n-from strawberry.object_type import _process_type\n+from strawberry.object_type import _process_type, _wrap_dataclass\n+from strawberry.types.type_resolver import _get_fields\n from strawberry.types.types import FederationTypeParams, TypeDefinition\n \n from .exceptions import MissingFieldsListError, UnregisteredTypeException\n@@ -91,34 +92,36 @@\n             if name in fields_set\n         ]\n \n-        cls_annotations = getattr(cls, \"__annotations__\", {})\n+        wrapped = _wrap_dataclass(cls)\n+        extra_fields = _get_fields(wrapped)\n+\n         all_fields.extend(\n             (\n                 (\n-                    name,\n-                    type_,\n-                    StrawberryField(\n-                        python_name=name,\n-                        graphql_name=None,\n-                        type_annotation=type_,\n-                        # we need a default value when adding additional fields\n-                        # on top of a type generated from Pydantic, this is because\n-                        # Pydantic Optional fields always have None as default value\n-                        # which breaks dataclasses generation; as we can't define\n-                        # a field without a default value after one with a default value\n-                        # adding fields at the beginning won't work as we will also\n-                        # support default values on them (so the problem will be just\n-                        # shifted around)\n-                        default=None,\n-                    ),\n+                    field.name,\n+                    field.type,\n+                    field,\n                 )\n-                for name, type_ in cls_annotations.items()\n+                for field in extra_fields\n             )\n         )\n \n+        # Sort fields so that fields with missing defaults go first\n+        # because dataclasses require that fields with no defaults are defined\n+        # first\n+        missing_default = []\n+        has_default = []\n+        for field in all_fields:\n+            if field[2].default is dataclasses.MISSING:\n+                missing_default.append(field)\n+            else:\n+                has_default.append(field)\n+\n+        sorted_fields = missing_default + has_default\n+\n         cls = dataclasses.make_dataclass(\n             cls.__name__,\n-            all_fields,\n+            sorted_fields,\n         )\n \n         _process_type(\n", "issue": "Type resolver not called when extending from pydantic model\nI have 2 types, Category and Articles, and I want the Category type to return its related Articles(I have tried with other simpler types too), but when defining a resolver in the Category type its not being called:\r\n\r\n```python\r\ndef articles_helper(root):  \r\n    return []      #  <-whatever I return here, it always shows null\r\n   \r\n   \r\n@strawberry.experimental.pydantic.type(\r\n    model=Category,\r\n    fields=[\r\n        'title',\r\n        'description',\r\n        'content',\r\n        'template',\r\n        'slug',\r\n        'date_published',\r\n        'date_updated',\r\n    ])\r\nclass CategoryType(Category):\r\n    id: int\r\n    articles: Optional[List[ArticleType]] = strawberry.field(resolver=articles_helper)  # <- resolver not called\r\n```    \r\n\r\nQuery type:\r\n```python\r\n@strawberry.type()\r\nclass Query:\r\n    category: Optional[CategoryType] = field(resolver=get_category)  # this resolver is OK\r\n```\r\n\r\nAlways returns `null`:\r\n```\r\nQuery:\r\n\r\n{\r\n  category(categoryId: 1) {\r\n    id\r\n    title\r\n    articles {\r\n      title\r\n    }\r\n  }\r\n}\r\n\r\nResponse:\r\n\r\n{\r\n  \"data\": {\r\n    \"category\": {\r\n      \"id\": 1,\r\n      \"title\": \"test\",\r\n      \"articles\": null      <- always\r\n    }\r\n  }\r\n}\r\n```\r\n\r\n**I works when I don't extend from a pydantic model**\n", "before_files": [{"content": "import builtins\nimport dataclasses\nfrom functools import partial\nfrom typing import Any, Dict, List, Optional, Type\n\nfrom pydantic import BaseModel\nfrom pydantic.fields import ModelField\n\nfrom strawberry.arguments import UNSET\nfrom strawberry.experimental.pydantic.conversion import (\n    convert_pydantic_model_to_strawberry_class,\n)\nfrom strawberry.experimental.pydantic.fields import get_basic_type\nfrom strawberry.field import StrawberryField\nfrom strawberry.object_type import _process_type\nfrom strawberry.types.types import FederationTypeParams, TypeDefinition\n\nfrom .exceptions import MissingFieldsListError, UnregisteredTypeException\n\n\ndef replace_pydantic_types(type_: Any):\n    if hasattr(type_, \"__args__\"):\n        new_type = type_.copy_with(\n            tuple(replace_pydantic_types(t) for t in type_.__args__)\n        )\n\n        if isinstance(new_type, TypeDefinition):\n            # TODO: Not sure if this is necessary. No coverage in tests\n            # TODO: Unnecessary with StrawberryObject\n\n            new_type = builtins.type(\n                new_type.name,\n                (),\n                {\"_type_definition\": new_type},\n            )\n\n        return new_type\n\n    if issubclass(type_, BaseModel):\n        if hasattr(type_, \"_strawberry_type\"):\n            return type_._strawberry_type\n        else:\n            raise UnregisteredTypeException(type_)\n\n    return type_\n\n\ndef get_type_for_field(field: ModelField):\n    type_ = field.outer_type_\n    type_ = get_basic_type(type_)\n    type_ = replace_pydantic_types(type_)\n\n    if not field.required:\n        type_ = Optional[type_]\n\n    return type_\n\n\ndef type(\n    model: Type[BaseModel],\n    *,\n    fields: List[str],\n    name: Optional[str] = None,\n    is_input: bool = False,\n    is_interface: bool = False,\n    description: Optional[str] = None,\n    federation: Optional[FederationTypeParams] = None,\n):\n    def wrap(cls):\n        if not fields:\n            raise MissingFieldsListError(model)\n\n        model_fields = model.__fields__\n        fields_set = set(fields)\n\n        all_fields = [\n            (\n                name,\n                get_type_for_field(field),\n                StrawberryField(\n                    python_name=field.name,\n                    graphql_name=field.alias if field.has_alias else None,\n                    default=field.default if not field.required else UNSET,\n                    default_factory=(\n                        field.default_factory if field.default_factory else UNSET\n                    ),\n                    type_annotation=get_type_for_field(field),\n                ),\n            )\n            for name, field in model_fields.items()\n            if name in fields_set\n        ]\n\n        cls_annotations = getattr(cls, \"__annotations__\", {})\n        all_fields.extend(\n            (\n                (\n                    name,\n                    type_,\n                    StrawberryField(\n                        python_name=name,\n                        graphql_name=None,\n                        type_annotation=type_,\n                        # we need a default value when adding additional fields\n                        # on top of a type generated from Pydantic, this is because\n                        # Pydantic Optional fields always have None as default value\n                        # which breaks dataclasses generation; as we can't define\n                        # a field without a default value after one with a default value\n                        # adding fields at the beginning won't work as we will also\n                        # support default values on them (so the problem will be just\n                        # shifted around)\n                        default=None,\n                    ),\n                )\n                for name, type_ in cls_annotations.items()\n            )\n        )\n\n        cls = dataclasses.make_dataclass(\n            cls.__name__,\n            all_fields,\n        )\n\n        _process_type(\n            cls,\n            name=name,\n            is_input=is_input,\n            is_interface=is_interface,\n            description=description,\n            federation=federation,\n        )\n\n        model._strawberry_type = cls  # type: ignore\n\n        def from_pydantic(instance: Any, extra: Dict[str, Any] = None) -> Any:\n            return convert_pydantic_model_to_strawberry_class(\n                cls=cls, model_instance=instance, extra=extra\n            )\n\n        def to_pydantic(self) -> Any:\n            instance_kwargs = dataclasses.asdict(self)\n\n            return model(**instance_kwargs)\n\n        cls.from_pydantic = staticmethod(from_pydantic)\n        cls.to_pydantic = to_pydantic\n\n        return cls\n\n    return wrap\n\n\ninput = partial(type, is_input=True)\n", "path": "strawberry/experimental/pydantic/object_type.py"}], "after_files": [{"content": "import builtins\nimport dataclasses\nfrom functools import partial\nfrom typing import Any, Dict, List, Optional, Type\n\nfrom pydantic import BaseModel\nfrom pydantic.fields import ModelField\n\nfrom strawberry.arguments import UNSET\nfrom strawberry.experimental.pydantic.conversion import (\n    convert_pydantic_model_to_strawberry_class,\n)\nfrom strawberry.experimental.pydantic.fields import get_basic_type\nfrom strawberry.field import StrawberryField\nfrom strawberry.object_type import _process_type, _wrap_dataclass\nfrom strawberry.types.type_resolver import _get_fields\nfrom strawberry.types.types import FederationTypeParams, TypeDefinition\n\nfrom .exceptions import MissingFieldsListError, UnregisteredTypeException\n\n\ndef replace_pydantic_types(type_: Any):\n    if hasattr(type_, \"__args__\"):\n        new_type = type_.copy_with(\n            tuple(replace_pydantic_types(t) for t in type_.__args__)\n        )\n\n        if isinstance(new_type, TypeDefinition):\n            # TODO: Not sure if this is necessary. No coverage in tests\n            # TODO: Unnecessary with StrawberryObject\n\n            new_type = builtins.type(\n                new_type.name,\n                (),\n                {\"_type_definition\": new_type},\n            )\n\n        return new_type\n\n    if issubclass(type_, BaseModel):\n        if hasattr(type_, \"_strawberry_type\"):\n            return type_._strawberry_type\n        else:\n            raise UnregisteredTypeException(type_)\n\n    return type_\n\n\ndef get_type_for_field(field: ModelField):\n    type_ = field.outer_type_\n    type_ = get_basic_type(type_)\n    type_ = replace_pydantic_types(type_)\n\n    if not field.required:\n        type_ = Optional[type_]\n\n    return type_\n\n\ndef type(\n    model: Type[BaseModel],\n    *,\n    fields: List[str],\n    name: Optional[str] = None,\n    is_input: bool = False,\n    is_interface: bool = False,\n    description: Optional[str] = None,\n    federation: Optional[FederationTypeParams] = None,\n):\n    def wrap(cls):\n        if not fields:\n            raise MissingFieldsListError(model)\n\n        model_fields = model.__fields__\n        fields_set = set(fields)\n\n        all_fields = [\n            (\n                name,\n                get_type_for_field(field),\n                StrawberryField(\n                    python_name=field.name,\n                    graphql_name=field.alias if field.has_alias else None,\n                    default=field.default if not field.required else UNSET,\n                    default_factory=(\n                        field.default_factory if field.default_factory else UNSET\n                    ),\n                    type_annotation=get_type_for_field(field),\n                ),\n            )\n            for name, field in model_fields.items()\n            if name in fields_set\n        ]\n\n        wrapped = _wrap_dataclass(cls)\n        extra_fields = _get_fields(wrapped)\n\n        all_fields.extend(\n            (\n                (\n                    field.name,\n                    field.type,\n                    field,\n                )\n                for field in extra_fields\n            )\n        )\n\n        # Sort fields so that fields with missing defaults go first\n        # because dataclasses require that fields with no defaults are defined\n        # first\n        missing_default = []\n        has_default = []\n        for field in all_fields:\n            if field[2].default is dataclasses.MISSING:\n                missing_default.append(field)\n            else:\n                has_default.append(field)\n\n        sorted_fields = missing_default + has_default\n\n        cls = dataclasses.make_dataclass(\n            cls.__name__,\n            sorted_fields,\n        )\n\n        _process_type(\n            cls,\n            name=name,\n            is_input=is_input,\n            is_interface=is_interface,\n            description=description,\n            federation=federation,\n        )\n\n        model._strawberry_type = cls  # type: ignore\n\n        def from_pydantic(instance: Any, extra: Dict[str, Any] = None) -> Any:\n            return convert_pydantic_model_to_strawberry_class(\n                cls=cls, model_instance=instance, extra=extra\n            )\n\n        def to_pydantic(self) -> Any:\n            instance_kwargs = dataclasses.asdict(self)\n\n            return model(**instance_kwargs)\n\n        cls.from_pydantic = staticmethod(from_pydantic)\n        cls.to_pydantic = to_pydantic\n\n        return cls\n\n    return wrap\n\n\ninput = partial(type, is_input=True)\n", "path": "strawberry/experimental/pydantic/object_type.py"}]}