Skip to content

Commit

Permalink
Add default values to Context and RootValue type vars
Browse files Browse the repository at this point in the history
  • Loading branch information
patrick91 committed Dec 20, 2024
1 parent 6553c9e commit 62258da
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
10 changes: 5 additions & 5 deletions strawberry/http/typevars.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
from typing import TypeVar
from typing_extensions import TypeVar

Request = TypeVar("Request", contravariant=True)
Response = TypeVar("Response")
SubResponse = TypeVar("SubResponse")
WebSocketRequest = TypeVar("WebSocketRequest")
WebSocketResponse = TypeVar("WebSocketResponse")
Context = TypeVar("Context")
RootValue = TypeVar("RootValue")
Context = TypeVar("Context", default=None)
RootValue = TypeVar("RootValue", default=None)


__all__ = [
"Context",
"Request",
"Response",
"RootValue",
"SubResponse",
"WebSocketRequest",
"WebSocketResponse",
"Context",
"RootValue",
]
16 changes: 8 additions & 8 deletions tests/fastapi/test_context.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import asyncio
from typing import Any, AsyncGenerator, Dict
from typing import AsyncGenerator, Dict

import pytest

Expand Down Expand Up @@ -47,7 +47,7 @@ def get_context(custom_context: CustomContext = Depends(custom_context_dependenc

app = FastAPI()
schema = strawberry.Schema(query=Query)
graphql_app = GraphQLRouter[Any, None](schema=schema, context_getter=get_context)
graphql_app = GraphQLRouter(schema=schema, context_getter=get_context)
app.include_router(graphql_app, prefix="/graphql")

test_client = TestClient(app)
Expand Down Expand Up @@ -81,7 +81,7 @@ def get_context(custom_context: CustomContext = Depends()):

app = FastAPI()
schema = strawberry.Schema(query=Query)
graphql_app = GraphQLRouter[Any, None](schema=schema, context_getter=get_context)
graphql_app = GraphQLRouter(schema=schema, context_getter=get_context)
app.include_router(graphql_app, prefix="/graphql")

test_client = TestClient(app)
Expand Down Expand Up @@ -113,7 +113,7 @@ def get_context(value: str = Depends(custom_context_dependency)) -> Dict[str, st

app = FastAPI()
schema = strawberry.Schema(query=Query)
graphql_app = GraphQLRouter[Any, None](schema=schema, context_getter=get_context)
graphql_app = GraphQLRouter(schema=schema, context_getter=get_context)
app.include_router(graphql_app, prefix="/graphql")

test_client = TestClient(app)
Expand All @@ -138,7 +138,7 @@ def abc(self, info: strawberry.Info) -> str:

app = FastAPI()
schema = strawberry.Schema(query=Query)
graphql_app = GraphQLRouter[None, None](schema, context_getter=None)
graphql_app = GraphQLRouter(schema, context_getter=None)
app.include_router(graphql_app, prefix="/graphql")

test_client = TestClient(app)
Expand Down Expand Up @@ -169,7 +169,7 @@ def get_context(value: str = Depends(custom_context_dependency)) -> str:

app = FastAPI()
schema = strawberry.Schema(query=Query)
graphql_app = GraphQLRouter[Any, None](schema=schema, context_getter=get_context)
graphql_app = GraphQLRouter(schema=schema, context_getter=get_context)
app.include_router(graphql_app, prefix="/graphql")

test_client = TestClient(app)
Expand Down Expand Up @@ -213,7 +213,7 @@ def get_context(context: Context = Depends()) -> Context:

app = FastAPI()
schema = strawberry.Schema(query=Query, subscription=Subscription)
graphql_app = GraphQLRouter[Any, None](schema=schema, context_getter=get_context)
graphql_app = GraphQLRouter(schema=schema, context_getter=get_context)
app.include_router(graphql_app, prefix="/graphql")
test_client = TestClient(app)

Expand Down Expand Up @@ -287,7 +287,7 @@ def get_context(context: Context = Depends()) -> Context:

app = FastAPI()
schema = strawberry.Schema(query=Query, subscription=Subscription)
graphql_app = GraphQLRouter[Any, None](schema=schema, context_getter=get_context)
graphql_app = GraphQLRouter(schema=schema, context_getter=get_context)
app.include_router(graphql_app, prefix="/graphql")
test_client = TestClient(app)

Expand Down

0 comments on commit 62258da

Please sign in to comment.