Skip to content

Commit 94a591f

Browse files
committed
Improve error message for bad return from subscribe resolver
After asserting AsyncIterable is required, show what was received instead.
1 parent 86009a6 commit 94a591f

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

src/subscription/__tests__/subscribe-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -585,7 +585,7 @@ describe('Subscribe', () => {
585585
invalidEmailSchema,
586586
ast
587587
);
588-
}).to.throw('Subscription must return Async Iterable.');
588+
}).to.throw('Subscription must return AsyncIterable. Received: test');
589589
});
590590

591591
it('expects to have subscribe on type definition with iterator', () => {

src/subscription/subscribe.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -224,10 +224,12 @@ export function createSourceEventStream(
224224
throw subscription;
225225
}
226226

227-
invariant(
228-
isAsyncIterable(subscription),
229-
'Subscription must return Async Iterable.'
230-
);
227+
if (!isAsyncIterable(subscription)) {
228+
throw new Error(
229+
'Subscription must return Async Iterable. ' +
230+
'Received: ' + String(subscription)
231+
);
232+
}
231233

232234
return (subscription: any);
233235
}

0 commit comments

Comments
 (0)