|
14 | 14 | logger,
|
15 | 15 | package_version,
|
16 | 16 | _get_installed_modules,
|
| 17 | + async_any, |
17 | 18 | )
|
18 | 19 |
|
19 | 20 | try:
|
|
35 | 36 | SentryTracingExtensionSync as StrawberrySentrySyncExtension,
|
36 | 37 | )
|
37 | 38 | from strawberry.http import async_base_view, sync_base_view # type: ignore
|
| 39 | + from strawberry.types import ExecutionContext, ExecutionResult # type: ignore[import-not-found] |
38 | 40 | except ImportError:
|
39 | 41 | raise DidNotEnable("strawberry-graphql is not installed")
|
40 | 42 |
|
41 | 43 | from typing import TYPE_CHECKING
|
42 | 44 |
|
43 | 45 | if TYPE_CHECKING:
|
44 |
| - from typing import Any, Callable, Generator, List, Optional |
| 46 | + from typing import Any, Callable, Generator, List, Optional, Union |
45 | 47 | from graphql import GraphQLError, GraphQLResolveInfo # type: ignore
|
46 | 48 | from strawberry.http import GraphQLHTTPResponse
|
47 |
| - from strawberry.types import ExecutionContext, ExecutionResult # type: ignore |
| 49 | + from strawberry.types import SubscriptionExecutionResult |
48 | 50 | from sentry_sdk._types import Event, EventProcessor
|
49 | 51 |
|
50 | 52 |
|
@@ -291,13 +293,17 @@ def _patch_execute():
|
291 | 293 | old_execute_sync = strawberry_schema.execute_sync
|
292 | 294 |
|
293 | 295 | async def _sentry_patched_execute_async(*args, **kwargs):
|
294 |
| - # type: (Any, Any) -> ExecutionResult |
| 296 | + # type: (Any, Any) -> Union[ExecutionResult, SubscriptionExecutionResult] |
295 | 297 | result = await old_execute_async(*args, **kwargs)
|
296 | 298 |
|
297 | 299 | if sentry_sdk.get_client().get_integration(StrawberryIntegration) is None:
|
298 | 300 | return result
|
299 | 301 |
|
300 |
| - if "execution_context" in kwargs and result.errors: |
| 302 | + if "execution_context" in kwargs and ( |
| 303 | + result.errors |
| 304 | + if isinstance(result, ExecutionResult) |
| 305 | + else await async_any(r.errors async for r in result) |
| 306 | + ): |
301 | 307 | scope = sentry_sdk.get_isolation_scope()
|
302 | 308 | event_processor = _make_request_event_processor(kwargs["execution_context"])
|
303 | 309 | scope.add_event_processor(event_processor)
|
|
0 commit comments