Skip to content

Commit 36d4a54

Browse files
committed
Restore old behavior of subscribe_field().
Better to stay backward compatible in GraphQL-core 2.
1 parent 190069d commit 36d4a54

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

graphql/execution/executor.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,7 @@ def subscribe_fields(
267267
parent_type, # type: GraphQLObjectType
268268
source_value, # type: Any
269269
fields, # type: DefaultOrderedDict
270+
only_first_field=True, # type: bool
270271
):
271272
# type: (...) -> Observable
272273
subscriber_exe_context = SubscriberExecutionContext(exe_context)
@@ -290,7 +291,7 @@ def catch_error(error):
290291
observables = [] # type: List[Observable]
291292

292293
# TODO: Make sure this works with multiple fields (currently untested)
293-
# assert len(fields) == 1, "Can only subscribe one element at a time."
294+
# so we can remove the "only_first_field" argument.
294295

295296
for response_name, field_asts in fields.items():
296297
result = subscribe_field(
@@ -306,9 +307,11 @@ def catch_error(error):
306307
observable = result.catch_exception(catch_error).map(
307308
lambda data: map_result({response_name: data})
308309
)
310+
if only_first_field:
311+
return observable
309312
observables.append(observable)
310313

311-
return observables[0] if len(observables) == 1 else Observable.merge(observables)
314+
return Observable.merge(observables)
312315

313316

314317
def resolve_field(

0 commit comments

Comments
 (0)