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
strawberry.Parent
not supporting forward refs
#3481
Labels
bug
Something isn't working
Comments
patrick91
changed the title
Review/Revise & Maybe Correct Strawberry Docs On Parent Resolving
May 2, 2024
strawberry.Parent
not supporting forward refs
@andrewkruse I think you found a bug, this should work: from __future__ import annotations # NOTE: this
import strawberry
def get_full_name(user: strawberry.Parent[User]) -> str:
return f"{user.first_name} {user.last_name}"
@strawberry.type
class User:
first_name: str
last_name: str
full_name: str = strawberry.field(resolver=get_full_name)
@strawberry.type
class Query:
@strawberry.field
def user(self) -> User:
return User(first_name="John", last_name="Doe")
schema = strawberry.Schema(query=Query) but it doesn't work |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I would like the strawberry documentation on accessing parent with function resolvers on this page tweaked to be more clear, or maybe corrected?
From what I understand in the docs, its suggesting you end up with the following. However, this doesn't even run? I have tried swapping the definitions both directions, they have the same issue. I had to resort to the
self
method on a method resolver, which seems less desirable to me since the docs specifically call out that it might not work quite right everywhere.Perhaps there's a quirk in here where the structure of my file is part of the problem since everything is top level? I am using FastAPI, uvicorn and strawberry.
Upvote & Fund
The text was updated successfully, but these errors were encountered: