From 6531e3bbbc058428ab30f74d7a7f739fba324930 Mon Sep 17 00:00:00 2001 From: Lee Byron Date: Fri, 26 May 2017 17:29:16 -0700 Subject: [PATCH] Subscriptions: Test that source errors pass through. After discussion in #868, decided that errors emitted from a source event stream should be considered "internal" errors and pass through. --- src/subscription/__tests__/subscribe-test.js | 52 ++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/src/subscription/__tests__/subscribe-test.js b/src/subscription/__tests__/subscribe-test.js index d15e276fa0a..be58634abf0 100644 --- a/src/subscription/__tests__/subscribe-test.js +++ b/src/subscription/__tests__/subscribe-test.js @@ -714,4 +714,56 @@ describe('Subscribe', () => { await subscription.next() ).to.deep.equal({ value: undefined, done: true }); }); + + it('should pass through error thrown in source event stream', async () => { + const erroringEmailSchema = emailSchemaWithResolvers( + async function* () { + yield { email: { subject: 'Hello' } }; + throw new Error('test error'); + }, + email => email + ); + + const subscription = subscribe( + erroringEmailSchema, + parse(` + subscription { + importantEmail { + email { + subject + } + } + } + `) + ); + + const payload1 = await subscription.next(); + expect(payload1).to.deep.equal({ + done: false, + value: { + data: { + importantEmail: { + email: { + subject: 'Hello' + } + } + } + } + }); + + let expectedError; + try { + await subscription.next(); + } catch (error) { + expectedError = error; + } + + expect(expectedError).to.deep.equal(new Error('test error')); + + const payload2 = await subscription.next(); + expect(payload2).to.deep.equal({ + done: true, + value: undefined + }); + }); });