strawberry
strawberry copied to clipboard
Improve how we determine types for fields that have resolvers
This was prompted by this issue: https://github.com/strawberry-graphql/strawberry/issues/1887
Currently there are some cases where the behaviour we have might not be what one expects. And we could also improve how we handled cases where field type and resolver type don't match.
Based on this type:
def resolver() -> another_type:
...
@strawberry.type
class Example:
field: a_type
Here's a table of the current behaviours
field type | resolver return type | current behaviour | expected behaviour | current type | expected type |
---|---|---|---|---|---|
int | TypeVar("T") | no error | no error [1] | int | int |
int | int | no errors, no warnings | no errors, no warnings | int | int |
int | missing | no errors, no warning | no error, maybe a (opt-out) warning? | int | int |
int | str | no errors, no warnings | error | str | int |
[1] recently fixed here: https://github.com/strawberry-graphql/strawberry/pull/1891
A side note on #1891: there's actually a few missing cases that the previous PR misses. That PR only fixes the most simple case of the resolver returning TypeVar("T")
. My fault for missing the more complex cases. I have opened another issue and PR for this with some discussion questions there: https://github.com/strawberry-graphql/strawberry/issues/1899
I've noticed a separate issue with StrawberryList and type hinted resolvers that return list
or List
, but that has a separate mechanism, issue here #1901