Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolver error if using Parent type with strawberry.experimental.pydantic.type #3422

Open
ShtykovaAA opened this issue Mar 25, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@ShtykovaAA
Copy link

ShtykovaAA commented Mar 25, 2024

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.
Fund with Polar
@ShtykovaAA ShtykovaAA added the bug Something isn't working label Mar 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant