Skip to content

Commit

Permalink
Remove dead code, fix coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
kristjanvalur committed Jul 19, 2023
1 parent 4795e9b commit 7a06a5f
Showing 1 changed file with 12 additions and 25 deletions.
37 changes: 12 additions & 25 deletions strawberry/subscriptions/protocols/graphql_transport_ws/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,34 +311,20 @@ async def handle_operation(
await operation.send_message(
ErrorMessage(id=operation.id, payload=payload)
)
self.schema.process_errors(result_source.errors)
if operation.operation_type == OperationType.SUBSCRIPTION:
self.schema.process_errors(result_source.errors)
return

try:
async for result in result_source:
if (
result.errors
and operation.operation_type != OperationType.SUBSCRIPTION
):
error_payload = [err.formatted for err in result.errors]
error_message = ErrorMessage(
id=operation.id, payload=error_payload
)
await operation.send_message(error_message)
# don't need to call schema.process_errors() here because
# it was already done by schema.execute()
return
else:
next_payload = {"data": result.data}
if result.errors:
self.schema.process_errors(result.errors)
next_payload["errors"] = [
err.formatted for err in result.errors
]
next_message = NextMessage(
id=operation.id, payload=next_payload
)
await operation.send_message(next_message)
next_payload = {"data": result.data}
if result.errors:
self.schema.process_errors(result.errors)
next_payload["errors"] = [
err.formatted for err in result.errors
]
next_message = NextMessage(id=operation.id, payload=next_payload)
await operation.send_message(next_message)
await operation.send_message(CompleteMessage(id=operation.id))
finally:
# Close the AsyncGenerator in case of errors or cancellation
Expand Down Expand Up @@ -423,8 +409,9 @@ def __init__(
self.task: Optional[asyncio.Task] = None

async def send_message(self, message: GraphQLTransportMessage) -> None:
# defensive check, should never happen
if self.completed:
return
return # pragma: no cover
if isinstance(message, (CompleteMessage, ErrorMessage)):
self.completed = True
# de-register the operation _before_ sending the final message
Expand Down

0 comments on commit 7a06a5f

Please sign in to comment.