strawberry-graphql 0.247.1__py3-none-any.whl → 0.247.2__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.
@@ -245,41 +245,42 @@ class BaseGraphQLTransportWSHandler:
245
245
  elif hasattr(self.context, "connection_params"):
246
246
  self.context.connection_params = self.connection_params
247
247
 
248
+ operation = Operation(
249
+ self,
250
+ message.id,
251
+ operation_type,
252
+ message.payload.query,
253
+ message.payload.variables,
254
+ message.payload.operationName,
255
+ )
256
+
257
+ operation.task = asyncio.create_task(self.run_operation(operation))
258
+ self.operations[message.id] = operation
259
+
260
+ async def run_operation(self, operation: Operation) -> None:
261
+ """The operation task's top level method. Cleans-up and de-registers the operation once it is done."""
262
+ # TODO: Handle errors in this method using self.handle_task_exception()
263
+
248
264
  result_source: Awaitable[ExecutionResult] | Awaitable[SubscriptionResult]
249
265
 
250
266
  # Get an AsyncGenerator yielding the results
251
- if operation_type == OperationType.SUBSCRIPTION:
267
+ if operation.operation_type == OperationType.SUBSCRIPTION:
252
268
  result_source = self.schema.subscribe(
253
- query=message.payload.query,
254
- variable_values=message.payload.variables,
255
- operation_name=message.payload.operationName,
269
+ query=operation.query,
270
+ variable_values=operation.variables,
271
+ operation_name=operation.operation_name,
256
272
  context_value=self.context,
257
273
  root_value=self.root_value,
258
274
  )
259
275
  else:
260
276
  result_source = self.schema.execute(
261
- query=message.payload.query,
262
- variable_values=message.payload.variables,
277
+ query=operation.query,
278
+ variable_values=operation.variables,
263
279
  context_value=self.context,
264
280
  root_value=self.root_value,
265
- operation_name=message.payload.operationName,
281
+ operation_name=operation.operation_name,
266
282
  )
267
283
 
268
- operation = Operation(self, message.id, operation_type)
269
-
270
- # Create task to handle this subscription, reserve the operation ID
271
- operation.task = asyncio.create_task(
272
- self.operation_task(result_source, operation)
273
- )
274
- self.operations[message.id] = operation
275
-
276
- async def operation_task(
277
- self,
278
- result_source: Awaitable[ExecutionResult] | Awaitable[SubscriptionResult],
279
- operation: Operation,
280
- ) -> None:
281
- """The operation task's top level method. Cleans-up and de-registers the operation once it is done."""
282
- # TODO: Handle errors in this method using self.handle_task_exception()
283
284
  try:
284
285
  first_res_or_agen = await result_source
285
286
  # that's an immediate error we should end the operation
@@ -340,17 +341,32 @@ class BaseGraphQLTransportWSHandler:
340
341
  class Operation:
341
342
  """A class encapsulating a single operation with its id. Helps enforce protocol state transition."""
342
343
 
343
- __slots__ = ["handler", "id", "operation_type", "completed", "task"]
344
+ __slots__ = [
345
+ "handler",
346
+ "id",
347
+ "operation_type",
348
+ "query",
349
+ "variables",
350
+ "operation_name",
351
+ "completed",
352
+ "task",
353
+ ]
344
354
 
345
355
  def __init__(
346
356
  self,
347
357
  handler: BaseGraphQLTransportWSHandler,
348
358
  id: str,
349
359
  operation_type: OperationType,
360
+ query: str,
361
+ variables: Optional[Dict[str, Any]],
362
+ operation_name: Optional[str],
350
363
  ) -> None:
351
364
  self.handler = handler
352
365
  self.id = id
353
366
  self.operation_type = operation_type
367
+ self.query = query
368
+ self.variables = variables
369
+ self.operation_name = operation_name
354
370
  self.completed = False
355
371
  self.task: Optional[asyncio.Task] = None
356
372
 
@@ -5,7 +5,6 @@ from contextlib import suppress
5
5
  from typing import (
6
6
  TYPE_CHECKING,
7
7
  AsyncGenerator,
8
- Awaitable,
9
8
  Dict,
10
9
  Optional,
11
10
  cast,
@@ -37,7 +36,6 @@ from strawberry.utils.debug import pretty_print_graphql_operation
37
36
  if TYPE_CHECKING:
38
37
  from strawberry.http.async_base_view import AsyncWebSocketAdapter
39
38
  from strawberry.schema import BaseSchema
40
- from strawberry.schema.subscribe import SubscriptionResult
41
39
 
42
40
 
43
41
  class BaseGraphQLWSHandler:
@@ -136,15 +134,9 @@ class BaseGraphQLWSHandler:
136
134
  if self.debug:
137
135
  pretty_print_graphql_operation(operation_name, query, variables)
138
136
 
139
- result_source = self.schema.subscribe(
140
- query=query,
141
- variable_values=variables,
142
- operation_name=operation_name,
143
- context_value=self.context,
144
- root_value=self.root_value,
137
+ result_handler = self.handle_async_results(
138
+ operation_id, query, operation_name, variables
145
139
  )
146
-
147
- result_handler = self.handle_async_results(result_source, operation_id)
148
140
  self.tasks[operation_id] = asyncio.create_task(result_handler)
149
141
 
150
142
  async def handle_stop(self, message: OperationMessage) -> None:
@@ -160,11 +152,19 @@ class BaseGraphQLWSHandler:
160
152
 
161
153
  async def handle_async_results(
162
154
  self,
163
- result_source: Awaitable[SubscriptionResult],
164
155
  operation_id: str,
156
+ query: str,
157
+ operation_name: Optional[str],
158
+ variables: Optional[Dict[str, object]],
165
159
  ) -> None:
166
160
  try:
167
- agen_or_err = await result_source
161
+ agen_or_err = await self.schema.subscribe(
162
+ query=query,
163
+ variable_values=variables,
164
+ operation_name=operation_name,
165
+ context_value=self.context,
166
+ root_value=self.root_value,
167
+ )
168
168
  if isinstance(agen_or_err, PreExecutionError):
169
169
  assert agen_or_err.errors
170
170
  error_payload = agen_or_err.errors[0].formatted
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: strawberry-graphql
3
- Version: 0.247.1
3
+ Version: 0.247.2
4
4
  Summary: A library for creating GraphQL APIs
5
5
  Home-page: https://strawberry.rocks/
6
6
  License: MIT
@@ -187,10 +187,10 @@ strawberry/static/pathfinder.html,sha256=0DPx9AmJ2C_sJstFXnWOz9k5tVQHeHaK7qdVY4l
187
187
  strawberry/subscriptions/__init__.py,sha256=1VGmiCzFepqRFyCikagkUoHHdoTG3XYlFu9GafoQMws,170
188
188
  strawberry/subscriptions/protocols/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
189
189
  strawberry/subscriptions/protocols/graphql_transport_ws/__init__.py,sha256=wN6dkMu6WiaIZTE19PGoN9xXpIN_RdDE_q7F7ZgjCxk,138
190
- strawberry/subscriptions/protocols/graphql_transport_ws/handlers.py,sha256=pxP_yeEqXku3_AHh-Ev9BdHBn8iTfwKo4wrTo8RKz8g,14486
190
+ strawberry/subscriptions/protocols/graphql_transport_ws/handlers.py,sha256=_h-xNf_ZRtjn8PGbxZk3u9qTR-NNNCevdgaFF0uXciw,14728
191
191
  strawberry/subscriptions/protocols/graphql_transport_ws/types.py,sha256=udYxzGtwjETYvY5f23org0t-aY4cimTjEGFYUR3idaY,2596
192
192
  strawberry/subscriptions/protocols/graphql_ws/__init__.py,sha256=ijn1A1O0Fzv5p9n-jw3T5H7M3oxbN4gbxRaepN7HyJk,553
193
- strawberry/subscriptions/protocols/graphql_ws/handlers.py,sha256=IabXcES66aBA8aE2h2o73gwdp6iZ5HG9Hm2G5TOTuNc,7739
193
+ strawberry/subscriptions/protocols/graphql_ws/handlers.py,sha256=tQmQjoA-x4yXLHbjmq7r7fFnNPluIcc7EiYgQSFbiZ0,7740
194
194
  strawberry/subscriptions/protocols/graphql_ws/types.py,sha256=CKm4Hy95p6H9u_-QyWdxipwzNeeDIWtilP3RRp8vjPw,1050
195
195
  strawberry/test/__init__.py,sha256=U3B5Ng7C_H8GpCpfvgZZcfADMw6cor5hm78gS3nDdMI,115
196
196
  strawberry/test/client.py,sha256=Va7J1tIjZ6PxbOqPl57jSp5lNLOZSueHPmrUuUx5sRY,6462
@@ -230,8 +230,8 @@ strawberry/utils/logging.py,sha256=U1cseHGquN09YFhFmRkiphfASKCyK0HUZREImPgVb0c,7
230
230
  strawberry/utils/operation.py,sha256=SSXxN-vMqdHO6W2OZtip-1z7y4_A-eTVFdhDvhKeLCk,1193
231
231
  strawberry/utils/str_converters.py,sha256=KGd7QH90RevaJjH6SQEkiVVsb8KuhJr_wv5AsI7UzQk,897
232
232
  strawberry/utils/typing.py,sha256=3xws5kxSQGsp8BnYyUwClvxXNzZakMAuOPoq1rjHRuk,14252
233
- strawberry_graphql-0.247.1.dist-info/LICENSE,sha256=m-XnIVUKqlG_AWnfi9NReh9JfKhYOB-gJfKE45WM1W8,1072
234
- strawberry_graphql-0.247.1.dist-info/METADATA,sha256=eb7SR0I78_-i_gttEvj0BVWxHZky6TUv6nAlfqgJxWs,7758
235
- strawberry_graphql-0.247.1.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
236
- strawberry_graphql-0.247.1.dist-info/entry_points.txt,sha256=Nk7-aT3_uEwCgyqtHESV9H6Mc31cK-VAvhnQNTzTb4k,49
237
- strawberry_graphql-0.247.1.dist-info/RECORD,,
233
+ strawberry_graphql-0.247.2.dist-info/LICENSE,sha256=m-XnIVUKqlG_AWnfi9NReh9JfKhYOB-gJfKE45WM1W8,1072
234
+ strawberry_graphql-0.247.2.dist-info/METADATA,sha256=UNSXeMuxxVcoA8hC-8-CP-I7jeo-4R8Syg8W-kIA-ZE,7758
235
+ strawberry_graphql-0.247.2.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
236
+ strawberry_graphql-0.247.2.dist-info/entry_points.txt,sha256=Nk7-aT3_uEwCgyqtHESV9H6Mc31cK-VAvhnQNTzTb4k,49
237
+ strawberry_graphql-0.247.2.dist-info/RECORD,,