Skip to content

Commit

Permalink
Subscriptions: Test that source errors pass through.
Browse files Browse the repository at this point in the history
After discussion in #868, decided that errors emitted from a source event stream should be considered "internal" errors and pass through.
  • Loading branch information
leebyron committed May 27, 2017
1 parent f9d5b48 commit 6531e3b
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions src/subscription/__tests__/subscribe-test.js
Expand Up @@ -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
});
});
});

0 comments on commit 6531e3b

Please sign in to comment.