Skip to content

Commit

Permalink
test + deprecate class
Browse files Browse the repository at this point in the history
  • Loading branch information
Birdi7 committed May 8, 2024
1 parent 04985ca commit 407de1c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 6 deletions.
15 changes: 9 additions & 6 deletions strawberry/starlite/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from dataclasses import dataclass
from datetime import timedelta
from typing import TYPE_CHECKING, Any, Dict, Mapping, Optional, Tuple, Union, cast
from typing_extensions import deprecated

from starlite import (
BackgroundTasks,
Expand Down Expand Up @@ -118,6 +119,10 @@ async def get_root_value(self) -> Any:
return await self._get_root_value()


@deprecated(
"The `starlite` integration is deprecated, please use `litestar` instead.",
stacklevel=2,
)
class StarliteRequestAdapter(AsyncHTTPRequestAdapter):
def __init__(self, request: Request[Any, Any]) -> None:
self.request = request
Expand Down Expand Up @@ -153,6 +158,10 @@ def __init__(self) -> None:
self.response: Optional[Response] = None


@deprecated(
"The `starlite` integration is deprecated, please use `litestar` instead.",
stacklevel=2,
)
def make_graphql_controller(
schema: BaseSchema,
path: str = "",
Expand All @@ -172,12 +181,6 @@ def make_graphql_controller(
),
connection_init_wait_timeout: timedelta = timedelta(minutes=1),
) -> Type[Controller]:
warnings.warn(
"The `starlite` integration is deprecated, please use `litestar` instead.",
DeprecationWarning,
stacklevel=2,
)

routes_path = path

if context_getter is None:
Expand Down
21 changes: 21 additions & 0 deletions tests/starlite/test_context.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from typing import Dict

import pytest

import strawberry

try:
Expand Down Expand Up @@ -181,3 +183,22 @@ def something(self, info: strawberry.Info) -> str:

assert response.json() == {"data": {"something": "foo"}}
assert task_complete


def test_starlite_usage_triggers_deprecation_warning():
@strawberry.type
class Query:
@strawberry.field
def abc(self, info: strawberry.Info) -> str:
assert info.context.get("request") is not None
assert info.context.get("strawberry") is None
return "abc"

schema = strawberry.Schema(query=Query)

with pytest.deprecated_call():
graphql_controller = make_graphql_controller(
path="/graphql", schema=schema, context_getter=None
)
with pytest.deprecated_call():
app = Starlite(route_handlers=[graphql_controller])

0 comments on commit 407de1c

Please sign in to comment.