There's an example in strawberry docs that shows how to return a dict from a resolver and get it automatically converted to a GraphQL type. It does not work, when returned type implements an interface.
Reproduction:
def custom_resolver(obj, field):
try:
return obj[field]
except (KeyError, TypeError):
return getattr(obj, field)
@strawberry.interface
class UserInterface:
name: str
@strawberry.type
class Client(UserInterface):
companyName: str
@strawberry.type
class Query:
def user(self, info) -> UserInterface: # this won't type check, but will work at runtime
return {"name": "Patrick", "companyName": "company", "__typename": "Client"}
schema = strawberry.Schema(
query=Query, types=[Client], config=StrawberryConfig(default_resolver=custom_resolver)
)
It does not work when type hint on function return type is either UserInterface
nor Client
. Client
needs to stop implementing interface for it to start working.
I've checked it with debugger and when it implements the interface it does not even go into the custom_resolver
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