Skip to content

Commit

Permalink
(imp) fastapi: GraphQLRouter typing
Browse files Browse the repository at this point in the history
  • Loading branch information
alexey-pelykh committed Feb 12, 2025
1 parent 4c4e07b commit c7bd3eb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
4 changes: 4 additions & 0 deletions RELEASE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Release type: patch

This release adjusts the fastapi `GraphQLRouter` typing to redeclare
`Context` and `RootValue` as generic parameters.
13 changes: 9 additions & 4 deletions strawberry/fastapi/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
TYPE_CHECKING,
Any,
Callable,
Generic,
Optional,
Union,
cast,
Expand Down Expand Up @@ -55,6 +56,7 @@ class GraphQLRouter(
Request, Response, Response, WebSocket, WebSocket, Context, RootValue
],
APIRouter,
Generic[Context, RootValue],
):
allow_queries_via_get = True
request_adapter_class = ASGIRequestAdapter
Expand All @@ -66,8 +68,9 @@ async def __get_root_value() -> None:

@staticmethod
def __get_context_getter(
custom_getter: Callable[
..., Union[Optional[CustomContext], Awaitable[Optional[CustomContext]]]
custom_getter: Union[
Callable[..., Optional[Context]],
Callable[..., Awaitable[Optional[Context]]],
],
) -> Callable[..., Awaitable[CustomContext]]:
async def dependency(
Expand Down Expand Up @@ -125,8 +128,10 @@ def __init__(
keep_alive_interval: float = 1,
debug: bool = False,
root_value_getter: Optional[Callable[[], RootValue]] = None,
context_getter: Optional[
Callable[..., Union[Optional[Context], Awaitable[Optional[Context]]]]
context_getter: Union[
None,
Callable[..., Optional[Context]],
Callable[..., Awaitable[Optional[Context]]],
] = None,
subscription_protocols: Sequence[str] = (
GRAPHQL_TRANSPORT_WS_PROTOCOL,
Expand Down

0 comments on commit c7bd3eb

Please sign in to comment.