|
1 | 1 | from inspect import isawaitable
|
2 |
| -from typing import Any, AsyncGenerator, AsyncIterator, Awaitable, Coroutine, cast |
| 2 | +from typing import AsyncGenerator, Awaitable, cast |
3 | 3 |
|
4 | 4 | from graphql import DocumentNode, ExecutionResult, GraphQLSchema, execute, subscribe
|
5 | 5 |
|
@@ -50,27 +50,16 @@ async def execute(
|
50 | 50 | async def subscribe(
|
51 | 51 | self, document: DocumentNode, *args, **kwargs,
|
52 | 52 | ) -> AsyncGenerator[ExecutionResult, None]:
|
53 |
| - """Send a query and receive the results using an async generator |
54 |
| -
|
55 |
| - The query can be a graphql query, mutation or subscription |
| 53 | + """Send a subscription and receive the results using an async generator |
56 | 54 |
|
57 | 55 | The results are sent as an ExecutionResult object
|
58 | 56 | """
|
59 | 57 |
|
60 |
| - subscribe_result = subscribe(self.schema, document, *args, **kwargs) |
| 58 | + subscribe_result = await subscribe(self.schema, document, *args, **kwargs) |
61 | 59 |
|
62 | 60 | if isinstance(subscribe_result, ExecutionResult):
|
63 |
| - yield ExecutionResult |
| 61 | + yield subscribe_result |
64 | 62 |
|
65 | 63 | else:
|
66 |
| - # if we don't get an ExecutionResult, then we should receive |
67 |
| - # a Coroutine returning an AsyncIterator[ExecutionResult] |
68 |
| - |
69 |
| - subscribe_coro = cast( |
70 |
| - Coroutine[Any, Any, AsyncIterator[ExecutionResult]], subscribe_result |
71 |
| - ) |
72 |
| - |
73 |
| - subscribe_generator = await subscribe_coro |
74 |
| - |
75 |
| - async for result in subscribe_generator: |
| 64 | + async for result in subscribe_result: |
76 | 65 | yield result
|
0 commit comments