strawberry-graphql 0.250.0__py3-none-any.whl → 0.250.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.
@@ -12,14 +12,9 @@ from typing import (
12
12
 
13
13
  from strawberry.http.exceptions import NonTextMessageReceived, WebSocketDisconnected
14
14
  from strawberry.subscriptions.protocols.graphql_ws.types import (
15
- CompleteMessage,
16
- ConnectionAckMessage,
17
- ConnectionErrorMessage,
18
15
  ConnectionInitMessage,
19
- ConnectionKeepAliveMessage,
20
16
  ConnectionTerminateMessage,
21
17
  DataMessage,
22
- ErrorMessage,
23
18
  OperationMessage,
24
19
  StartMessage,
25
20
  StopMessage,
@@ -93,15 +88,13 @@ class BaseGraphQLWSHandler:
93
88
  async def handle_connection_init(self, message: ConnectionInitMessage) -> None:
94
89
  payload = message.get("payload")
95
90
  if payload is not None and not isinstance(payload, dict):
96
- error_message: ConnectionErrorMessage = {"type": "connection_error"}
97
- await self.websocket.send_json(error_message)
91
+ await self.send_message({"type": "connection_error"})
98
92
  await self.websocket.close(code=1000, reason="")
99
93
  return
100
94
 
101
95
  self.connection_params = payload
102
96
 
103
- connection_ack_message: ConnectionAckMessage = {"type": "connection_ack"}
104
- await self.websocket.send_json(connection_ack_message)
97
+ await self.send_message({"type": "connection_ack"})
105
98
 
106
99
  if self.keep_alive:
107
100
  keep_alive_handler = self.handle_keep_alive()
@@ -139,8 +132,7 @@ class BaseGraphQLWSHandler:
139
132
  async def handle_keep_alive(self) -> None:
140
133
  assert self.keep_alive_interval
141
134
  while True:
142
- data: ConnectionKeepAliveMessage = {"type": "ka"}
143
- await self.websocket.send_json(data)
135
+ await self.send_message({"type": "ka"})
144
136
  await asyncio.sleep(self.keep_alive_interval)
145
137
 
146
138
  async def handle_async_results(
@@ -160,26 +152,22 @@ class BaseGraphQLWSHandler:
160
152
  )
161
153
  if isinstance(agen_or_err, PreExecutionError):
162
154
  assert agen_or_err.errors
163
- error_payload = agen_or_err.errors[0].formatted
164
- error_message: ErrorMessage = {
165
- "type": "error",
166
- "id": operation_id,
167
- "payload": error_payload,
168
- }
169
- await self.websocket.send_json(error_message)
155
+ await self.send_message(
156
+ {
157
+ "type": "error",
158
+ "id": operation_id,
159
+ "payload": agen_or_err.errors[0].formatted,
160
+ }
161
+ )
170
162
  else:
171
163
  self.subscriptions[operation_id] = agen_or_err
172
164
 
173
165
  async for result in agen_or_err:
174
- await self.send_data(result, operation_id)
166
+ await self.send_data_message(result, operation_id)
175
167
 
176
- await self.websocket.send_json(
177
- CompleteMessage({"type": "complete", "id": operation_id})
178
- )
168
+ await self.send_message({"type": "complete", "id": operation_id})
179
169
  except asyncio.CancelledError:
180
- await self.websocket.send_json(
181
- CompleteMessage({"type": "complete", "id": operation_id})
182
- )
170
+ await self.send_message({"type": "complete", "id": operation_id})
183
171
 
184
172
  async def cleanup_operation(self, operation_id: str) -> None:
185
173
  if operation_id in self.subscriptions:
@@ -192,7 +180,7 @@ class BaseGraphQLWSHandler:
192
180
  await self.tasks[operation_id]
193
181
  del self.tasks[operation_id]
194
182
 
195
- async def send_data(
183
+ async def send_data_message(
196
184
  self, execution_result: ExecutionResult, operation_id: str
197
185
  ) -> None:
198
186
  data_message: DataMessage = {
@@ -209,7 +197,10 @@ class BaseGraphQLWSHandler:
209
197
  if execution_result.extensions:
210
198
  data_message["payload"]["extensions"] = execution_result.extensions
211
199
 
212
- await self.websocket.send_json(data_message)
200
+ await self.send_message(data_message)
201
+
202
+ async def send_message(self, message: OperationMessage) -> None:
203
+ await self.websocket.send_json(message)
213
204
 
214
205
 
215
206
  __all__ = ["BaseGraphQLWSHandler"]
@@ -78,6 +78,7 @@ OperationMessage = Union[
78
78
  DataMessage,
79
79
  ErrorMessage,
80
80
  CompleteMessage,
81
+ ConnectionKeepAliveMessage,
81
82
  ]
82
83
 
83
84
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: strawberry-graphql
3
- Version: 0.250.0
3
+ Version: 0.250.1
4
4
  Summary: A library for creating GraphQL APIs
5
5
  Home-page: https://strawberry.rocks/
6
6
  License: MIT
@@ -189,8 +189,8 @@ strawberry/subscriptions/protocols/graphql_transport_ws/__init__.py,sha256=wN6dk
189
189
  strawberry/subscriptions/protocols/graphql_transport_ws/handlers.py,sha256=R9QCGHJ_lf0gmNf_wzt4Ow-HFA5ulFsGUiNo_K3CHkI,14104
190
190
  strawberry/subscriptions/protocols/graphql_transport_ws/types.py,sha256=AtKPEyFuNIKgnIIBD-MC4kAYFQ6uhXeq3xyRF6Dh-hg,2181
191
191
  strawberry/subscriptions/protocols/graphql_ws/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
192
- strawberry/subscriptions/protocols/graphql_ws/handlers.py,sha256=oM0o85zC24LpBjtVq8VakKx2hBGL0kb3Q9yl0GyFLS8,7614
193
- strawberry/subscriptions/protocols/graphql_ws/types.py,sha256=diZ36w56Nb_YmgfWXe6uXGiQOKmWIVjNEkcM-PkjaSs,1939
192
+ strawberry/subscriptions/protocols/graphql_ws/handlers.py,sha256=BmUh_IRJRW7xKCvZD7ewJK0rT8iERzkff53FaJJGRlk,7224
193
+ strawberry/subscriptions/protocols/graphql_ws/types.py,sha256=WvCZVhxFRkojvOFKiDuXPtighsEJkQU-I9y4Vgo5c4w,1971
194
194
  strawberry/test/__init__.py,sha256=U3B5Ng7C_H8GpCpfvgZZcfADMw6cor5hm78gS3nDdMI,115
195
195
  strawberry/test/client.py,sha256=Va7J1tIjZ6PxbOqPl57jSp5lNLOZSueHPmrUuUx5sRY,6462
196
196
  strawberry/tools/__init__.py,sha256=pdGpZx8wpq03VfUZJyF9JtYxZhGqzzxCiipsalWxJX4,127
@@ -229,8 +229,8 @@ strawberry/utils/logging.py,sha256=U1cseHGquN09YFhFmRkiphfASKCyK0HUZREImPgVb0c,7
229
229
  strawberry/utils/operation.py,sha256=SSXxN-vMqdHO6W2OZtip-1z7y4_A-eTVFdhDvhKeLCk,1193
230
230
  strawberry/utils/str_converters.py,sha256=KGd7QH90RevaJjH6SQEkiVVsb8KuhJr_wv5AsI7UzQk,897
231
231
  strawberry/utils/typing.py,sha256=G6k2wWD1TDQ9WFk-Togekj_hTVFqHV-g7Phf2Wu41ms,14380
232
- strawberry_graphql-0.250.0.dist-info/LICENSE,sha256=m-XnIVUKqlG_AWnfi9NReh9JfKhYOB-gJfKE45WM1W8,1072
233
- strawberry_graphql-0.250.0.dist-info/METADATA,sha256=4VaLyKu8LPZoMQwYXdWBxpVCoVtEM5JVKH6bST7gY3U,7758
234
- strawberry_graphql-0.250.0.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
235
- strawberry_graphql-0.250.0.dist-info/entry_points.txt,sha256=Nk7-aT3_uEwCgyqtHESV9H6Mc31cK-VAvhnQNTzTb4k,49
236
- strawberry_graphql-0.250.0.dist-info/RECORD,,
232
+ strawberry_graphql-0.250.1.dist-info/LICENSE,sha256=m-XnIVUKqlG_AWnfi9NReh9JfKhYOB-gJfKE45WM1W8,1072
233
+ strawberry_graphql-0.250.1.dist-info/METADATA,sha256=Jf2Ze4K3PJP13i8aXpx7lDOhACKcrHjD0dzZek8ke8g,7758
234
+ strawberry_graphql-0.250.1.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
235
+ strawberry_graphql-0.250.1.dist-info/entry_points.txt,sha256=Nk7-aT3_uEwCgyqtHESV9H6Mc31cK-VAvhnQNTzTb4k,49
236
+ strawberry_graphql-0.250.1.dist-info/RECORD,,