Resolver error if using Parent type with strawberry.experimental.pydantic.type
Opened this issue · 0 comments
ShtykovaAA commented
Hi everyone!
I found in docs example of using type Parent https://strawberry.rocks/docs/types/resolvers#defining-resolvers-as-methods, so I followed the docs and saw that it works only @strawberry.type
So here my example with SQLModel class SomeExtensionSQLModel
witch transforms to strawberry.type
SomeExtension
by using strawberry.experimental.pydantic.type
decorator
import strawberry
from dataclasses import dataclass
from sqlmodel import SQLModel
class SomeExtensionSQLModel(SQLModel):
login: str
@strawberry.experimental.pydantic.type(SomeExtensionSQLModel, all_fields=True)
class SomeExtension:
...
@dataclass
class UserRow(SomeExtension):
id_: str
@strawberry.type
class User(SomeExtension):
@strawberry.field
@staticmethod
async def name(parent: strawberry.Parent[UserRow]) -> str:
return f"User Number {parent.id_}"
@strawberry.type
class Query:
@strawberry.field
def user(self) -> User:
return UserRow(id_="1234", login='123')
And I got error:
Traceback (most recent call last):
File "/Users/19653277/Library/Caches/pypoetry/virtualenvs/datamarket-backend-NWPanlm1-py3.10/lib/python3.10/site-packages/graphql/execution/execute.py", line 540, in execute_field
completed = self.complete_value(
File "/Users/19653277/Library/Caches/pypoetry/virtualenvs/datamarket-backend-NWPanlm1-py3.10/lib/python3.10/site-packages/graphql/execution/execute.py", line 612, in complete_value
completed = self.complete_value(
File "/Users/19653277/Library/Caches/pypoetry/virtualenvs/datamarket-backend-NWPanlm1-py3.10/lib/python3.10/site-packages/graphql/execution/execute.py", line 650, in complete_value
return self.complete_object_value(
File "/Users/19653277/Library/Caches/pypoetry/virtualenvs/datamarket-backend-NWPanlm1-py3.10/lib/python3.10/site-packages/graphql/execution/execute.py", line 924, in complete_object_value
raise invalid_return_type_error(return_type, result, field_nodes)
graphql.error.graphql_error.GraphQLError: Expected value of type 'User' but got: <UserRow instance>```
But if the class SomeExtension
declared like this:
@strawberry.type
class SomeExtension:
login: str
everything is alright
Upvote & Fund
- We're using Polar.sh 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.