Skip to content

Commit

Permalink
Mypy support for SubscriptionExecutionResult
Browse files Browse the repository at this point in the history
  • Loading branch information
kristjanvalur committed Sep 7, 2024
1 parent 4084639 commit d17a4d4
Showing 1 changed file with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
SubscribeMessage,
SubscribeMessagePayload,
)
from strawberry.types import ExecutionResult
from strawberry.types.graphql import OperationType
from strawberry.types.unset import UNSET
from strawberry.utils.debug import pretty_print_graphql_operation
Expand All @@ -42,7 +43,7 @@
from strawberry.subscriptions.protocols.graphql_transport_ws.types import (
GraphQLTransportMessage,
)
from strawberry.types import ExecutionResult



class BaseGraphQLTransportWSHandler(ABC):
Expand Down Expand Up @@ -274,13 +275,16 @@ async def start_operation() -> Union[AsyncGenerator[Any, None], Any]:
root_value=root_value,
operation_name=message.payload.operationName,
)
# Note: result may be SubscriptionExecutionResult or ExecutionResult
# now, but we don't support the former properly yet, hence the "ignore" below.

# Both validation and execution errors are handled the same way.
if result.errors:
if isinstance(result, ExecutionResult) and result.errors:
return result

# create AsyncGenerator returning a single result
async def single_result() -> AsyncIterator[ExecutionResult]:
yield result
yield result # type: ignore

return single_result()

Expand Down

0 comments on commit d17a4d4

Please sign in to comment.