|
21 | 21 | from ..language import DocumentNode |
22 | 22 | from ..pyutils import Path, inspect |
23 | 23 | from ..type import GraphQLFieldResolver, GraphQLSchema |
24 | | -from ..utilities import get_operation_root_type |
25 | 24 | from .map_async_iterator import MapAsyncIterator |
26 | 25 |
|
27 | 26 | __all__ = ["subscribe", "create_source_event_stream"] |
@@ -163,25 +162,32 @@ async def create_source_event_stream( |
163 | 162 |
|
164 | 163 | async def execute_subscription(context: ExecutionContext) -> AsyncIterable[Any]: |
165 | 164 | schema = context.schema |
166 | | - type_ = get_operation_root_type(schema, context.operation) |
167 | | - fields = collect_fields( |
| 165 | + |
| 166 | + root_type = schema.subscription_type |
| 167 | + if root_type is None: |
| 168 | + raise GraphQLError( |
| 169 | + "Schema is not configured to execute subscription operation.", |
| 170 | + context.operation, |
| 171 | + ) |
| 172 | + |
| 173 | + root_fields = collect_fields( |
168 | 174 | schema, |
169 | 175 | context.fragments, |
170 | 176 | context.variable_values, |
171 | | - type_, |
| 177 | + root_type, |
172 | 178 | context.operation.selection_set, |
173 | 179 | ) |
174 | | - response_name, field_nodes = next(iter(fields.items())) |
175 | | - field_def = get_field_def(schema, type_, field_nodes[0]) |
| 180 | + response_name, field_nodes = next(iter(root_fields.items())) |
| 181 | + field_def = get_field_def(schema, root_type, field_nodes[0]) |
176 | 182 |
|
177 | 183 | if not field_def: |
178 | 184 | field_name = field_nodes[0].name.value |
179 | 185 | raise GraphQLError( |
180 | 186 | f"The subscription field '{field_name}' is not defined.", field_nodes |
181 | 187 | ) |
182 | 188 |
|
183 | | - path = Path(None, response_name, type_.name) |
184 | | - info = context.build_resolve_info(field_def, field_nodes, type_, path) |
| 189 | + path = Path(None, response_name, root_type.name) |
| 190 | + info = context.build_resolve_info(field_def, field_nodes, root_type, path) |
185 | 191 |
|
186 | 192 | # Implements the "ResolveFieldEventStream" algorithm from GraphQL specification. |
187 | 193 | # It differs from "ResolveFieldValue" due to providing a different `resolveFn`. |
|
0 commit comments