Skip to content

Commit

Permalink
Fix root value and context getter types (#3712)
Browse files Browse the repository at this point in the history
  • Loading branch information
DoctorJohn authored Nov 23, 2024
1 parent 8a41f87 commit ba0fb83
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
5 changes: 5 additions & 0 deletions RELEASE.md
Original file line number Diff line number Diff line change
@@ -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.
5 changes: 3 additions & 2 deletions strawberry/asgi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from json import JSONDecodeError
from typing import (
TYPE_CHECKING,
Any,
AsyncGenerator,
AsyncIterator,
Callable,
Expand Down Expand Up @@ -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(
Expand Down
12 changes: 7 additions & 5 deletions strawberry/django/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit ba0fb83

Please sign in to comment.