strawberry icon indicating copy to clipboard operation
strawberry copied to clipboard

Flask dispatch_request() return type is overly restrictive

Open twm opened this issue 2 years ago • 0 comments

strawberry.GraphQLView.dispatch_request() is typed as returning flask.Request, which is much more restrictive than the superclass method return type:

Union[Response, str, bytes, Dict[str, Any], Iterator[str], Iterator[bytes], Tuple[Union[Response, str, bytes, Dict[str, Any], Iterator[str], Iterator[bytes]], Union[Headers, Dict[str, Union[str, List[str], Tuple[str, …]]], List[Tuple[str, Union[str, List[str], Tuple[str, …]]]]]], Tuple[Union[Response, str, bytes, Dict[str, Any], Iterator[str], Iterator[bytes]], int], Tuple[Union[Response, str, bytes, Dict[str, Any], Iterator[str], Iterator[bytes]], int, Union[Headers, Dict[str, Union[str, List[str], Tuple[str, …]]], List[Tuple[str, Union[str, List[str], Tuple[str, …]]]]]], WSGIApplication]

This is inconvenient when subclassing GraphQLView to, say, conditionally redirect() as that function returns a werkzeug.wrappers.Response that isn't compatible with flask.Response.

I think that it would be best to inherit the return type from the parent class.

System Information

  • Operating system: N/A
  • Strawberry version (if applicable): 0.111.1

twm avatar May 10 '22 00:05 twm