Skip to content

Commit 42dbced

Browse files
committed
Slight change in subscribe_fields() (#242)
Allow merging multiple fields into one result.
1 parent baf5fe4 commit 42dbced

File tree

2 files changed

+10
-11
lines changed

2 files changed

+10
-11
lines changed

graphql/execution/executor.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -306,10 +306,9 @@ def catch_error(error):
306306
observable = result.catch_exception(catch_error).map(
307307
lambda data: map_result({response_name: data})
308308
)
309-
return observable
310309
observables.append(observable)
311310

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

314313

315314
def resolve_field(

graphql/execution/tests/test_subscribe.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# type: ignore
21
from collections import OrderedDict, namedtuple
32
from rx import Observable, Observer
43
from rx.subjects import Subject
@@ -142,6 +141,7 @@ class inbox(object):
142141
)
143142
]
144143

144+
@staticmethod
145145
def importantEmail():
146146
return stream
147147

@@ -209,10 +209,11 @@ def test_accepts_multiple_subscription_fields_defined_in_schema():
209209
message="Tests are good",
210210
unread=True,
211211
)
212-
l = []
213-
stream.subscribe(l.append)
212+
inbox = []
213+
stream.subscribe(inbox.append)
214214
send_important_email(email)
215-
assert l[0][0] == email
215+
assert len(inbox) == 1
216+
assert inbox[0][0] == email
216217

217218

218219
def test_accepts_type_definition_with_sync_subscribe_function():
@@ -241,11 +242,11 @@ def test_accepts_type_definition_with_sync_subscribe_function():
241242
message="Tests are good",
242243
unread=True,
243244
)
244-
l = []
245-
subscription.subscribe(l.append)
245+
inbox = []
246+
subscription.subscribe(inbox.append)
246247
send_important_email(email)
247-
248-
assert l # [0].data == {'importantEmail': None}
248+
assert len(inbox) == 1
249+
assert inbox[0].data == {"importantEmail": None}
249250

250251

251252
def test_throws_an_error_if_subscribe_does_not_return_an_iterator():
@@ -422,6 +423,5 @@ def test_event_order_is_correct_for_multiple_publishes():
422423
}
423424

424425
assert len(payload) == 2
425-
print(payload)
426426
assert payload[0].data == expected_payload1
427427
assert payload[1].data == expected_payload2

0 commit comments

Comments
 (0)