strawberry icon indicating copy to clipboard operation
strawberry copied to clipboard

Fields with resolvers raise Type Errors when using Generic Subclasses

Open invokermain opened this issue 2 years ago • 1 comments

Describe the Bug

Following on from: https://github.com/strawberry-graphql/strawberry/pull/1891

The case where a field's resolver has a subclassed generic return type still raises a Type Error. The isinstance check is too weak.

See this gist for examples: https://gist.github.com/invokermain/31c783c76dd26e1da862cbe5218d2500

System Information

  • Strawberry version (if applicable): 0.111.2

Additional Context

There is a wider discussion about resolver return type hint behaviour here: https://github.com/strawberry-graphql/strawberry/issues/1896

invokermain avatar May 10 '22 13:05 invokermain

Behavior table:

Let T = TypeVar("T") ... the extended table might like:

field type resolver return type current behaviour expected behaviour current type expected type
int T no error no error [1] int int
int GenericClass[T] runtime error no errors, no warnings int int
int Optional[T] runtime error no errors, no warnings int int

[1] recently fixed here: https://github.com/strawberry-graphql/strawberry/pull/1891

invokermain avatar May 10 '22 14:05 invokermain