Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/execution/__tests__/subscribe-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,7 @@ describe('Subscription Initialization Phase', () => {

const result = subscribe({ schema, document });
expectJSON(result).toDeepEqual({
data: null,
errors: [
{
message:
Expand All @@ -451,6 +452,7 @@ describe('Subscription Initialization Phase', () => {

const result = subscribe({ schema, document });
expectJSON(result).toDeepEqual({
data: null,
errors: [
{
message: 'The subscription field "unknownField" is not defined.',
Expand All @@ -477,6 +479,7 @@ describe('Subscription Initialization Phase', () => {

it('throws an error if subscribe does not return an iterator', async () => {
const expectedResult = {
data: null,
errors: [
{
message:
Expand All @@ -498,6 +501,7 @@ describe('Subscription Initialization Phase', () => {

it('resolves to an error for subscription resolver errors', async () => {
const expectedResult = {
data: null,
errors: [
{
message: 'test error',
Expand Down
7 changes: 5 additions & 2 deletions src/execution/execute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1141,12 +1141,15 @@ export function createSourceEventStream(
try {
const eventStream = executeSubscription(exeContext);
if (isPromise(eventStream)) {
return eventStream.then(undefined, (error) => ({ errors: [error] }));
return eventStream.then(undefined, (error) => ({
data: null,
errors: [error],
}));
}

return eventStream;
} catch (error) {
return { errors: [error] };
return { data: null, errors: [error] };
}
}

Expand Down