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.
and it works like it should in Python, but there might be cases where it doesn’t properly follow Python’s semantics
def get_full_name(parent: strawberry.Parent[User2]) -> str:
return f"{parent.first_name} {parent.last_name}"
@strawberry.type
class User2:
first_name: str
last_name: str
full_name: str = strawberry.field(resolver=get_full_name)
Traceback (most recent call last):
File "/Users/.../Library/Application Support/JetBrains/IntelliJIdea2024.1/plugins/python/helpers/pydev/pydevd.py", line 1535, in _exec
pydev_imports.execfile(file, globals, locals) # execute the script
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/.../Library/Application Support/JetBrains/IntelliJIdea2024.1/plugins/python/helpers/pydev/_pydev_imps/_pydev_execfile.py", line 18, in execfile
exec(compile(contents+"\n", file, 'exec'), glob, loc)
File "/Users/.../src/api/python-graphql-poc/src/main.py", line 21, in <module>
def get_full_name(parent: strawberry.Parent[User2]) -> str:
^^^^^
NameError: name 'User2' is not defined
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.
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too