diff --git a/RELEASE.md b/RELEASE.md new file mode 100644 index 0000000000..7c6a33952a --- /dev/null +++ b/RELEASE.md @@ -0,0 +1,5 @@ +Release type: minor + +In this release, the return types of the `get_root_value` and `get_context` +methods were updated to be consistent across all view integrations. Before this +release, the return types used by the ASGI and Django views were too generic. diff --git a/strawberry/asgi/__init__.py b/strawberry/asgi/__init__.py index 90eacd8bd2..9075b6eabe 100644 --- a/strawberry/asgi/__init__.py +++ b/strawberry/asgi/__init__.py @@ -5,7 +5,6 @@ from json import JSONDecodeError from typing import ( TYPE_CHECKING, - Any, AsyncGenerator, AsyncIterator, Callable, @@ -185,7 +184,9 @@ async def __call__(self, scope: Scope, receive: Receive, send: Send) -> None: else: # pragma: no cover raise ValueError("Unknown scope type: {!r}".format(scope["type"])) - async def get_root_value(self, request: Union[Request, WebSocket]) -> Optional[Any]: + async def get_root_value( + self, request: Union[Request, WebSocket] + ) -> Optional[RootValue]: return None async def get_context( diff --git a/strawberry/django/views.py b/strawberry/django/views.py index 3db192e4c4..47cd2b1d98 100644 --- a/strawberry/django/views.py +++ b/strawberry/django/views.py @@ -221,8 +221,8 @@ class GraphQLView( def get_root_value(self, request: HttpRequest) -> Optional[RootValue]: return None - def get_context(self, request: HttpRequest, response: HttpResponse) -> Any: - return StrawberryDjangoContext(request=request, response=response) + def get_context(self, request: HttpRequest, response: HttpResponse) -> Context: + return StrawberryDjangoContext(request=request, response=response) # type: ignore def get_sub_response(self, request: HttpRequest) -> TemporalHttpResponse: return TemporalHttpResponse() @@ -276,11 +276,13 @@ def as_view(cls, **initkwargs: Any) -> Callable[..., HttpResponse]: return view - async def get_root_value(self, request: HttpRequest) -> Any: + async def get_root_value(self, request: HttpRequest) -> Optional[RootValue]: return None - async def get_context(self, request: HttpRequest, response: HttpResponse) -> Any: - return StrawberryDjangoContext(request=request, response=response) + async def get_context( + self, request: HttpRequest, response: HttpResponse + ) -> Context: + return StrawberryDjangoContext(request=request, response=response) # type: ignore async def get_sub_response(self, request: HttpRequest) -> TemporalHttpResponse: return TemporalHttpResponse()