strawberry-graphql 0.243.1__py3-none-any.whl → 0.244.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. strawberry/aiohttp/views.py +58 -44
  2. strawberry/asgi/__init__.py +62 -61
  3. strawberry/channels/__init__.py +1 -6
  4. strawberry/channels/handlers/base.py +2 -2
  5. strawberry/channels/handlers/http_handler.py +18 -1
  6. strawberry/channels/handlers/ws_handler.py +113 -58
  7. strawberry/codegen/query_codegen.py +8 -6
  8. strawberry/django/views.py +19 -1
  9. strawberry/fastapi/router.py +27 -45
  10. strawberry/flask/views.py +15 -1
  11. strawberry/http/async_base_view.py +136 -16
  12. strawberry/http/exceptions.py +4 -0
  13. strawberry/http/typevars.py +11 -1
  14. strawberry/litestar/controller.py +77 -86
  15. strawberry/quart/views.py +15 -1
  16. strawberry/sanic/views.py +21 -1
  17. strawberry/subscriptions/protocols/graphql_transport_ws/handlers.py +41 -40
  18. strawberry/subscriptions/protocols/graphql_ws/handlers.py +46 -45
  19. {strawberry_graphql-0.243.1.dist-info → strawberry_graphql-0.244.1.dist-info}/METADATA +1 -1
  20. {strawberry_graphql-0.243.1.dist-info → strawberry_graphql-0.244.1.dist-info}/RECORD +23 -37
  21. strawberry/aiohttp/handlers/__init__.py +0 -6
  22. strawberry/aiohttp/handlers/graphql_transport_ws_handler.py +0 -62
  23. strawberry/aiohttp/handlers/graphql_ws_handler.py +0 -69
  24. strawberry/asgi/handlers/__init__.py +0 -6
  25. strawberry/asgi/handlers/graphql_transport_ws_handler.py +0 -66
  26. strawberry/asgi/handlers/graphql_ws_handler.py +0 -71
  27. strawberry/channels/handlers/graphql_transport_ws_handler.py +0 -62
  28. strawberry/channels/handlers/graphql_ws_handler.py +0 -72
  29. strawberry/fastapi/handlers/__init__.py +0 -6
  30. strawberry/fastapi/handlers/graphql_transport_ws_handler.py +0 -20
  31. strawberry/fastapi/handlers/graphql_ws_handler.py +0 -18
  32. strawberry/litestar/handlers/__init__.py +0 -0
  33. strawberry/litestar/handlers/graphql_transport_ws_handler.py +0 -60
  34. strawberry/litestar/handlers/graphql_ws_handler.py +0 -66
  35. {strawberry_graphql-0.243.1.dist-info → strawberry_graphql-0.244.1.dist-info}/LICENSE +0 -0
  36. {strawberry_graphql-0.243.1.dist-info → strawberry_graphql-0.244.1.dist-info}/WHEEL +0 -0
  37. {strawberry_graphql-0.243.1.dist-info → strawberry_graphql-0.244.1.dist-info}/entry_points.txt +0 -0
@@ -1,62 +0,0 @@
1
- from __future__ import annotations
2
-
3
- from typing import TYPE_CHECKING, Any, Callable, Optional
4
-
5
- from strawberry.subscriptions import GRAPHQL_TRANSPORT_WS_PROTOCOL
6
- from strawberry.subscriptions.protocols.graphql_transport_ws.handlers import (
7
- BaseGraphQLTransportWSHandler,
8
- )
9
-
10
- if TYPE_CHECKING:
11
- from datetime import timedelta
12
-
13
- from strawberry.channels.handlers.base import ChannelsWSConsumer
14
- from strawberry.schema import BaseSchema
15
-
16
-
17
- class GraphQLTransportWSHandler(BaseGraphQLTransportWSHandler):
18
- def __init__(
19
- self,
20
- schema: BaseSchema,
21
- debug: bool,
22
- connection_init_wait_timeout: timedelta,
23
- get_context: Callable,
24
- get_root_value: Callable,
25
- ws: ChannelsWSConsumer,
26
- ) -> None:
27
- super().__init__(schema, debug, connection_init_wait_timeout)
28
- self._get_context = get_context
29
- self._get_root_value = get_root_value
30
- self._ws = ws
31
-
32
- async def get_context(self) -> Any:
33
- return await self._get_context(
34
- request=self._ws, connection_params=self.connection_params
35
- )
36
-
37
- async def get_root_value(self) -> Any:
38
- return await self._get_root_value(request=self._ws)
39
-
40
- async def send_json(self, data: dict) -> None:
41
- await self._ws.send_json(data)
42
-
43
- async def close(self, code: int = 1000, reason: Optional[str] = None) -> None:
44
- # TODO: We are using `self._ws.base_send` directly instead of `self._ws.close`
45
- # because the later doesn't accept the `reason` argument.
46
- await self._ws.base_send(
47
- {
48
- "type": "websocket.close",
49
- "code": code,
50
- "reason": reason or "",
51
- }
52
- )
53
-
54
- async def handle_request(self) -> Any:
55
- await self._ws.accept(subprotocol=GRAPHQL_TRANSPORT_WS_PROTOCOL)
56
- self.on_request_accepted()
57
-
58
- async def handle_disconnect(self, code: int) -> None:
59
- await self.shutdown()
60
-
61
-
62
- __all__ = ["GraphQLTransportWSHandler"]
@@ -1,72 +0,0 @@
1
- from __future__ import annotations
2
-
3
- from contextlib import suppress
4
- from typing import TYPE_CHECKING, Any, Callable, Optional
5
-
6
- from strawberry.subscriptions import GRAPHQL_WS_PROTOCOL
7
- from strawberry.subscriptions.protocols.graphql_ws.handlers import BaseGraphQLWSHandler
8
-
9
- if TYPE_CHECKING:
10
- from strawberry.channels.handlers.base import ChannelsWSConsumer
11
- from strawberry.schema import BaseSchema
12
- from strawberry.subscriptions.protocols.graphql_ws.types import OperationMessage
13
-
14
-
15
- class GraphQLWSHandler(BaseGraphQLWSHandler):
16
- def __init__(
17
- self,
18
- schema: BaseSchema,
19
- debug: bool,
20
- keep_alive: bool,
21
- keep_alive_interval: float,
22
- get_context: Callable,
23
- get_root_value: Callable,
24
- ws: ChannelsWSConsumer,
25
- ) -> None:
26
- super().__init__(schema, debug, keep_alive, keep_alive_interval)
27
- self._get_context = get_context
28
- self._get_root_value = get_root_value
29
- self._ws = ws
30
-
31
- async def get_context(self) -> Any:
32
- return await self._get_context(
33
- request=self._ws, connection_params=self.connection_params
34
- )
35
-
36
- async def get_root_value(self) -> Any:
37
- return await self._get_root_value(request=self._ws)
38
-
39
- async def send_json(self, data: OperationMessage) -> None:
40
- await self._ws.send_json(data)
41
-
42
- async def close(self, code: int = 1000, reason: Optional[str] = None) -> None:
43
- # TODO: We are using `self._ws.base_send` directly instead of `self._ws.close`
44
- # because the latler doesn't accept the `reason` argument.
45
- await self._ws.base_send(
46
- {
47
- "type": "websocket.close",
48
- "code": code,
49
- "reason": reason or "",
50
- }
51
- )
52
-
53
- async def handle_request(self) -> Any:
54
- await self._ws.accept(subprotocol=GRAPHQL_WS_PROTOCOL)
55
-
56
- async def handle_disconnect(self, code: int) -> None:
57
- if self.keep_alive_task:
58
- self.keep_alive_task.cancel()
59
- with suppress(BaseException):
60
- await self.keep_alive_task
61
-
62
- for operation_id in list(self.subscriptions.keys()):
63
- await self.cleanup_operation(operation_id)
64
-
65
- async def handle_invalid_message(self, error_message: str) -> None:
66
- # This is not part of the BaseGraphQLWSHandler's interface, but the
67
- # channels integration is a high level wrapper that forwards this to
68
- # both us and the BaseGraphQLTransportWSHandler.
69
- await self.close(code=1002, reason=error_message)
70
-
71
-
72
- __all__ = ["GraphQLWSHandler"]
@@ -1,6 +0,0 @@
1
- from strawberry.fastapi.handlers.graphql_transport_ws_handler import (
2
- GraphQLTransportWSHandler,
3
- )
4
- from strawberry.fastapi.handlers.graphql_ws_handler import GraphQLWSHandler
5
-
6
- __all__ = ["GraphQLTransportWSHandler", "GraphQLWSHandler"]
@@ -1,20 +0,0 @@
1
- from typing import Any
2
-
3
- from strawberry.asgi.handlers import (
4
- GraphQLTransportWSHandler as BaseGraphQLTransportWSHandler,
5
- )
6
- from strawberry.fastapi.context import BaseContext
7
-
8
-
9
- class GraphQLTransportWSHandler(BaseGraphQLTransportWSHandler):
10
- async def get_context(self) -> Any:
11
- context = await self._get_context()
12
- if isinstance(context, BaseContext):
13
- context.connection_params = self.connection_params
14
- return context
15
-
16
- async def get_root_value(self) -> Any:
17
- return await self._get_root_value()
18
-
19
-
20
- __all__ = ["GraphQLTransportWSHandler"]
@@ -1,18 +0,0 @@
1
- from typing import Any
2
-
3
- from strawberry.asgi.handlers import GraphQLWSHandler as BaseGraphQLWSHandler
4
- from strawberry.fastapi.context import BaseContext
5
-
6
-
7
- class GraphQLWSHandler(BaseGraphQLWSHandler):
8
- async def get_context(self) -> Any:
9
- context = await self._get_context()
10
- if isinstance(context, BaseContext):
11
- context.connection_params = self.connection_params
12
- return context
13
-
14
- async def get_root_value(self) -> Any:
15
- return await self._get_root_value()
16
-
17
-
18
- __all__ = ["GraphQLWSHandler"]
File without changes
@@ -1,60 +0,0 @@
1
- from collections.abc import Callable
2
- from datetime import timedelta
3
- from typing import Any
4
-
5
- from litestar import WebSocket
6
- from litestar.exceptions import SerializationException, WebSocketDisconnect
7
- from strawberry.schema import BaseSchema
8
- from strawberry.subscriptions import GRAPHQL_TRANSPORT_WS_PROTOCOL
9
- from strawberry.subscriptions.protocols.graphql_transport_ws.handlers import (
10
- BaseGraphQLTransportWSHandler,
11
- )
12
-
13
-
14
- class GraphQLTransportWSHandler(BaseGraphQLTransportWSHandler):
15
- def __init__(
16
- self,
17
- schema: BaseSchema,
18
- debug: bool,
19
- connection_init_wait_timeout: timedelta,
20
- get_context: Callable,
21
- get_root_value: Callable,
22
- ws: WebSocket,
23
- ) -> None:
24
- super().__init__(schema, debug, connection_init_wait_timeout)
25
- self._get_context = get_context
26
- self._get_root_value = get_root_value
27
- self._ws = ws
28
-
29
- async def get_context(self) -> Any:
30
- return await self._get_context()
31
-
32
- async def get_root_value(self) -> Any:
33
- return await self._get_root_value()
34
-
35
- async def send_json(self, data: dict) -> None:
36
- await self._ws.send_json(data)
37
-
38
- async def close(self, code: int, reason: str) -> None:
39
- await self._ws.close(code=code, reason=reason)
40
-
41
- async def handle_request(self) -> None:
42
- await self._ws.accept(subprotocols=GRAPHQL_TRANSPORT_WS_PROTOCOL)
43
- self.on_request_accepted()
44
-
45
- try:
46
- while self._ws.connection_state != "disconnect":
47
- try:
48
- message = await self._ws.receive_json()
49
- except (SerializationException, ValueError): # noqa: PERF203
50
- error_message = "WebSocket message type must be text"
51
- await self.handle_invalid_message(error_message)
52
- else:
53
- await self.handle_message(message)
54
- except WebSocketDisconnect: # pragma: no cover
55
- pass
56
- finally:
57
- await self.shutdown()
58
-
59
-
60
- __all__ = ["GraphQLTransportWSHandler"]
@@ -1,66 +0,0 @@
1
- from collections.abc import Callable
2
- from contextlib import suppress
3
- from typing import Any, Optional
4
-
5
- from litestar import WebSocket
6
- from litestar.exceptions import SerializationException, WebSocketDisconnect
7
- from strawberry.schema import BaseSchema
8
- from strawberry.subscriptions import GRAPHQL_WS_PROTOCOL
9
- from strawberry.subscriptions.protocols.graphql_ws.handlers import BaseGraphQLWSHandler
10
- from strawberry.subscriptions.protocols.graphql_ws.types import OperationMessage
11
-
12
-
13
- class GraphQLWSHandler(BaseGraphQLWSHandler):
14
- def __init__(
15
- self,
16
- schema: BaseSchema,
17
- debug: bool,
18
- keep_alive: bool,
19
- keep_alive_interval: float,
20
- get_context: Callable,
21
- get_root_value: Callable,
22
- ws: WebSocket,
23
- ) -> None:
24
- super().__init__(schema, debug, keep_alive, keep_alive_interval)
25
- self._get_context = get_context
26
- self._get_root_value = get_root_value
27
- self._ws = ws
28
-
29
- async def get_context(self) -> Any:
30
- return await self._get_context()
31
-
32
- async def get_root_value(self) -> Any:
33
- return await self._get_root_value()
34
-
35
- async def send_json(self, data: OperationMessage) -> None:
36
- await self._ws.send_json(data)
37
-
38
- async def close(self, code: int = 1000, reason: Optional[str] = None) -> None:
39
- await self._ws.close(code=code, reason=reason)
40
-
41
- async def handle_request(self) -> Any:
42
- await self._ws.accept(subprotocols=GRAPHQL_WS_PROTOCOL)
43
-
44
- try:
45
- while self._ws.connection_state != "disconnect":
46
- try:
47
- message = await self._ws.receive_json()
48
- except (SerializationException, ValueError): # noqa: PERF203
49
- await self.close(
50
- code=1002, reason="WebSocket message type must be text"
51
- )
52
- else:
53
- await self.handle_message(message)
54
- except WebSocketDisconnect: # pragma: no cover
55
- pass
56
- finally:
57
- if self.keep_alive_task:
58
- self.keep_alive_task.cancel()
59
- with suppress(BaseException):
60
- await self.keep_alive_task
61
-
62
- for operation_id in list(self.subscriptions.keys()):
63
- await self.cleanup_operation(operation_id)
64
-
65
-
66
- __all__ = ["GraphQLWSHandler"]