Repository: strawberry-graphql/strawberry

Issue:
from_pydantic error if pydantic models contains contains fields that are resolver field in strawberry type
Hi :),
i have a pydantic model that i want to convert to strawberry type using from_pydantic() method. The pydantic model contains fields that are resolver field in the strawberry type model.

```python

from .pydantic_models import Post as PostModel

# Strawberry type 
@strawberry.experimental.pydantic.type(name="Post", model=PostModel)
class PostType:
    user: Optional[LazyType["UserType", "api_gateway.user"]] = strawberry.field(name="user", resolver=resolve_user)
    create_date: auto
    text: auto
```

```python

# pydantic_models.py

from pydantic import BaseModel

# pydantic model
class Post(BaseModel):
    user: Optional["User"]
    create_date: datetime = Field(default_factory=datetime.utcnow)
    text: str
```

**Actual Behavior**
----------------------------------
__init__() got an unexpected keyword argument user

**Steps to Reproduce the Problem**
----------------------------------
pydantic_post = Post(user=None, text="Hello World!") #create pydantic instance
posttype = PostType.from_pydantic(pydantic_post) # not work - error

This also not work:
pydantic_post = Post(text="Hello World!")
posttype = PostType.from_pydantic(pydantic_post) # also not work

Thx





Discussion:

Resolving patch:
diff --git a/strawberry/experimental/pydantic/conversion.py b/strawberry/experimental/pydantic/conversion.py
--- a/strawberry/experimental/pydantic/conversion.py
+++ b/strawberry/experimental/pydantic/conversion.py
@@ -66,8 +66,12 @@ def convert_pydantic_model_to_strawberry_class(cls, *, model_instance=None, extr
         data_from_model = (
             getattr(model_instance, python_name, None) if model_instance else None
         )
-        kwargs[python_name] = _convert_from_pydantic_to_strawberry_type(
-            field.type, data_from_model, extra=data_from_extra
-        )
+
+        # only convert and add fields to kwargs if they are present in the `__init__`
+        # method of the class
+        if field.init:
+            kwargs[python_name] = _convert_from_pydantic_to_strawberry_type(
+                field.type, data_from_model, extra=data_from_extra
+            )
 
     return cls(**kwargs)


Test patch:
diff --git a/tests/experimental/pydantic/test_conversion.py b/tests/experimental/pydantic/test_conversion.py
--- a/tests/experimental/pydantic/test_conversion.py
+++ b/tests/experimental/pydantic/test_conversion.py
@@ -650,3 +650,27 @@ class UserInput:
 
     assert user.age == 1
     assert user.password is None
+
+
+def test_can_convert_pydantic_type_to_strawberry_with_additional_field_resolvers():
+    def some_resolver() -> int:
+        return 84
+
+    class UserModel(pydantic.BaseModel):
+        password: Optional[str]
+        new_age: int
+
+    @strawberry.experimental.pydantic.type(UserModel)
+    class User:
+        password: strawberry.auto
+        new_age: int = strawberry.field(resolver=some_resolver)
+
+        @strawberry.field
+        def age() -> int:
+            return 42
+
+    origin_user = UserModel(password="abc", new_age=21)
+    user = User.from_pydantic(origin_user)
+    assert user.password == "abc"
+    assert User._type_definition.fields[0].base_resolver() == 84
+    assert User._type_definition.fields[1].base_resolver() == 42