strawberry-graphql 0.243.1__py3-none-any.whl → 0.244.0__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.
- strawberry/aiohttp/views.py +58 -44
- strawberry/asgi/__init__.py +62 -61
- strawberry/channels/__init__.py +1 -6
- strawberry/channels/handlers/base.py +2 -2
- strawberry/channels/handlers/http_handler.py +18 -1
- strawberry/channels/handlers/ws_handler.py +113 -58
- strawberry/django/views.py +19 -1
- strawberry/fastapi/router.py +27 -45
- strawberry/flask/views.py +15 -1
- strawberry/http/async_base_view.py +136 -16
- strawberry/http/exceptions.py +4 -0
- strawberry/http/typevars.py +11 -1
- strawberry/litestar/controller.py +77 -86
- strawberry/quart/views.py +15 -1
- strawberry/sanic/views.py +21 -1
- strawberry/subscriptions/protocols/graphql_transport_ws/handlers.py +41 -40
- strawberry/subscriptions/protocols/graphql_ws/handlers.py +46 -45
- {strawberry_graphql-0.243.1.dist-info → strawberry_graphql-0.244.0.dist-info}/METADATA +1 -1
- {strawberry_graphql-0.243.1.dist-info → strawberry_graphql-0.244.0.dist-info}/RECORD +22 -36
- strawberry/aiohttp/handlers/__init__.py +0 -6
- strawberry/aiohttp/handlers/graphql_transport_ws_handler.py +0 -62
- strawberry/aiohttp/handlers/graphql_ws_handler.py +0 -69
- strawberry/asgi/handlers/__init__.py +0 -6
- strawberry/asgi/handlers/graphql_transport_ws_handler.py +0 -66
- strawberry/asgi/handlers/graphql_ws_handler.py +0 -71
- strawberry/channels/handlers/graphql_transport_ws_handler.py +0 -62
- strawberry/channels/handlers/graphql_ws_handler.py +0 -72
- strawberry/fastapi/handlers/__init__.py +0 -6
- strawberry/fastapi/handlers/graphql_transport_ws_handler.py +0 -20
- strawberry/fastapi/handlers/graphql_ws_handler.py +0 -18
- strawberry/litestar/handlers/__init__.py +0 -0
- strawberry/litestar/handlers/graphql_transport_ws_handler.py +0 -60
- strawberry/litestar/handlers/graphql_ws_handler.py +0 -66
- {strawberry_graphql-0.243.1.dist-info → strawberry_graphql-0.244.0.dist-info}/LICENSE +0 -0
- {strawberry_graphql-0.243.1.dist-info → strawberry_graphql-0.244.0.dist-info}/WHEEL +0 -0
- {strawberry_graphql-0.243.1.dist-info → strawberry_graphql-0.244.0.dist-info}/entry_points.txt +0 -0
@@ -1,69 +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 aiohttp import http, web
|
7
|
-
from strawberry.subscriptions import GRAPHQL_WS_PROTOCOL
|
8
|
-
from strawberry.subscriptions.protocols.graphql_ws.handlers import BaseGraphQLWSHandler
|
9
|
-
|
10
|
-
if TYPE_CHECKING:
|
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
|
-
request: web.Request,
|
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._request = request
|
30
|
-
self._ws = web.WebSocketResponse(protocols=[GRAPHQL_WS_PROTOCOL])
|
31
|
-
|
32
|
-
async def get_context(self) -> Any:
|
33
|
-
return await self._get_context(request=self._request, response=self._ws)
|
34
|
-
|
35
|
-
async def get_root_value(self) -> Any:
|
36
|
-
return await self._get_root_value(request=self._request)
|
37
|
-
|
38
|
-
async def send_json(self, data: OperationMessage) -> None:
|
39
|
-
await self._ws.send_json(data)
|
40
|
-
|
41
|
-
async def close(self, code: int = 1000, reason: Optional[str] = None) -> None:
|
42
|
-
message = reason.encode() if reason else b""
|
43
|
-
await self._ws.close(code=code, message=message)
|
44
|
-
|
45
|
-
async def handle_request(self) -> Any:
|
46
|
-
await self._ws.prepare(self._request)
|
47
|
-
|
48
|
-
try:
|
49
|
-
async for ws_message in self._ws: # type: http.WSMessage
|
50
|
-
if ws_message.type == http.WSMsgType.TEXT:
|
51
|
-
message: OperationMessage = ws_message.json()
|
52
|
-
await self.handle_message(message)
|
53
|
-
else:
|
54
|
-
await self.close(
|
55
|
-
code=1002, reason="WebSocket message type must be text"
|
56
|
-
)
|
57
|
-
finally:
|
58
|
-
if self.keep_alive_task:
|
59
|
-
self.keep_alive_task.cancel()
|
60
|
-
with suppress(BaseException):
|
61
|
-
await self.keep_alive_task
|
62
|
-
|
63
|
-
for operation_id in list(self.subscriptions.keys()):
|
64
|
-
await self.cleanup_operation(operation_id)
|
65
|
-
|
66
|
-
return self._ws
|
67
|
-
|
68
|
-
|
69
|
-
__all__ = ["GraphQLWSHandler"]
|
@@ -1,66 +0,0 @@
|
|
1
|
-
from __future__ import annotations
|
2
|
-
|
3
|
-
from typing import TYPE_CHECKING, Any, Callable
|
4
|
-
|
5
|
-
from starlette.websockets import WebSocketDisconnect, WebSocketState
|
6
|
-
|
7
|
-
from strawberry.subscriptions import GRAPHQL_TRANSPORT_WS_PROTOCOL
|
8
|
-
from strawberry.subscriptions.protocols.graphql_transport_ws.handlers import (
|
9
|
-
BaseGraphQLTransportWSHandler,
|
10
|
-
)
|
11
|
-
|
12
|
-
if TYPE_CHECKING:
|
13
|
-
from datetime import timedelta
|
14
|
-
|
15
|
-
from starlette.websockets import WebSocket
|
16
|
-
|
17
|
-
from strawberry.schema import BaseSchema
|
18
|
-
|
19
|
-
|
20
|
-
class GraphQLTransportWSHandler(BaseGraphQLTransportWSHandler):
|
21
|
-
def __init__(
|
22
|
-
self,
|
23
|
-
schema: BaseSchema,
|
24
|
-
debug: bool,
|
25
|
-
connection_init_wait_timeout: timedelta,
|
26
|
-
get_context: Callable,
|
27
|
-
get_root_value: Callable,
|
28
|
-
ws: WebSocket,
|
29
|
-
) -> None:
|
30
|
-
super().__init__(schema, debug, connection_init_wait_timeout)
|
31
|
-
self._get_context = get_context
|
32
|
-
self._get_root_value = get_root_value
|
33
|
-
self._ws = ws
|
34
|
-
|
35
|
-
async def get_context(self) -> Any:
|
36
|
-
return await self._get_context(request=self._ws, response=None)
|
37
|
-
|
38
|
-
async def get_root_value(self) -> Any:
|
39
|
-
return await self._get_root_value(request=self._ws)
|
40
|
-
|
41
|
-
async def send_json(self, data: dict) -> None:
|
42
|
-
await self._ws.send_json(data)
|
43
|
-
|
44
|
-
async def close(self, code: int, reason: str) -> None:
|
45
|
-
await self._ws.close(code=code, reason=reason)
|
46
|
-
|
47
|
-
async def handle_request(self) -> None:
|
48
|
-
await self._ws.accept(subprotocol=GRAPHQL_TRANSPORT_WS_PROTOCOL)
|
49
|
-
self.on_request_accepted()
|
50
|
-
|
51
|
-
try:
|
52
|
-
while self._ws.application_state != WebSocketState.DISCONNECTED:
|
53
|
-
try:
|
54
|
-
message = await self._ws.receive_json()
|
55
|
-
except KeyError: # noqa: PERF203
|
56
|
-
error_message = "WebSocket message type must be text"
|
57
|
-
await self.handle_invalid_message(error_message)
|
58
|
-
else:
|
59
|
-
await self.handle_message(message)
|
60
|
-
except WebSocketDisconnect: # pragma: no cover
|
61
|
-
pass
|
62
|
-
finally:
|
63
|
-
await self.shutdown()
|
64
|
-
|
65
|
-
|
66
|
-
__all__ = ["GraphQLTransportWSHandler"]
|
@@ -1,71 +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 starlette.websockets import WebSocketDisconnect, WebSocketState
|
7
|
-
|
8
|
-
from strawberry.subscriptions import GRAPHQL_WS_PROTOCOL
|
9
|
-
from strawberry.subscriptions.protocols.graphql_ws.handlers import BaseGraphQLWSHandler
|
10
|
-
|
11
|
-
if TYPE_CHECKING:
|
12
|
-
from starlette.websockets import WebSocket
|
13
|
-
|
14
|
-
from strawberry.schema import BaseSchema
|
15
|
-
from strawberry.subscriptions.protocols.graphql_ws.types import OperationMessage
|
16
|
-
|
17
|
-
|
18
|
-
class GraphQLWSHandler(BaseGraphQLWSHandler):
|
19
|
-
def __init__(
|
20
|
-
self,
|
21
|
-
schema: BaseSchema,
|
22
|
-
debug: bool,
|
23
|
-
keep_alive: bool,
|
24
|
-
keep_alive_interval: float,
|
25
|
-
get_context: Callable,
|
26
|
-
get_root_value: Callable,
|
27
|
-
ws: WebSocket,
|
28
|
-
) -> None:
|
29
|
-
super().__init__(schema, debug, keep_alive, keep_alive_interval)
|
30
|
-
self._get_context = get_context
|
31
|
-
self._get_root_value = get_root_value
|
32
|
-
self._ws = ws
|
33
|
-
|
34
|
-
async def get_context(self) -> Any:
|
35
|
-
return await self._get_context(request=self._ws, response=None)
|
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: OperationMessage) -> None:
|
41
|
-
await self._ws.send_json(data)
|
42
|
-
|
43
|
-
async def close(self, code: int = 1000, reason: Optional[str] = None) -> None:
|
44
|
-
await self._ws.close(code=code, reason=reason)
|
45
|
-
|
46
|
-
async def handle_request(self) -> Any:
|
47
|
-
await self._ws.accept(subprotocol=GRAPHQL_WS_PROTOCOL)
|
48
|
-
|
49
|
-
try:
|
50
|
-
while self._ws.application_state != WebSocketState.DISCONNECTED:
|
51
|
-
try:
|
52
|
-
message = await self._ws.receive_json()
|
53
|
-
except KeyError: # noqa: PERF203
|
54
|
-
await self.close(
|
55
|
-
code=1002, reason="WebSocket message type must be text"
|
56
|
-
)
|
57
|
-
else:
|
58
|
-
await self.handle_message(message)
|
59
|
-
except WebSocketDisconnect: # pragma: no cover
|
60
|
-
pass
|
61
|
-
finally:
|
62
|
-
if self.keep_alive_task:
|
63
|
-
self.keep_alive_task.cancel()
|
64
|
-
with suppress(BaseException):
|
65
|
-
await self.keep_alive_task
|
66
|
-
|
67
|
-
for operation_id in list(self.subscriptions.keys()):
|
68
|
-
await self.cleanup_operation(operation_id)
|
69
|
-
|
70
|
-
|
71
|
-
__all__ = ["GraphQLWSHandler"]
|
@@ -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,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"]
|
File without changes
|
File without changes
|
{strawberry_graphql-0.243.1.dist-info → strawberry_graphql-0.244.0.dist-info}/entry_points.txt
RENAMED
File without changes
|