Skip to content

Commit 7736a1a

Browse files
committed
Remove defer/stream support from subscriptions
See graphql/defer-stream-wg#55
1 parent 612abd3 commit 7736a1a

File tree

7 files changed

+21
-523
lines changed

7 files changed

+21
-523
lines changed

src/execution/__tests__/defer-test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -670,7 +670,7 @@ describe('Execute: defer directive', () => {
670670
rootValue: {},
671671
}),
672672
).to.throw(
673-
'Executing this GraphQL operation would unexpectedly produce multiple payloads (due to @defer or @stream directive)',
673+
'Executing this GraphQL operation would unexpectedly produce multiple payloads (due to @defer or @stream directive). Disable `@defer` or `@stream` by setting the `if` argument to `false`.',
674674
);
675675
});
676676

@@ -693,7 +693,7 @@ describe('Execute: defer directive', () => {
693693
errors: [
694694
{
695695
message:
696-
'Executing this GraphQL operation would unexpectedly produce multiple payloads (due to @defer or @stream directive)',
696+
'Executing this GraphQL operation would unexpectedly produce multiple payloads (due to @defer or @stream directive). Disable `@defer` or `@stream` by setting the `if` argument to `false`.',
697697
},
698698
],
699699
});

src/execution/__tests__/flattenAsyncIterable-test.ts

Lines changed: 0 additions & 149 deletions
This file was deleted.

src/execution/__tests__/subscribe-test.ts

Lines changed: 4 additions & 157 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,7 @@ import {
2121
import { GraphQLSchema } from '../../type/schema.js';
2222

2323
import type { ExecutionArgs, ExecutionResult } from '../execute.js';
24-
import {
25-
createSourceEventStream,
26-
experimentalSubscribeIncrementally,
27-
subscribe,
28-
} from '../execute.js';
24+
import { createSourceEventStream, subscribe } from '../execute.js';
2925

3026
import { SimplePubSub } from './simplePubSub.js';
3127

@@ -99,7 +95,6 @@ const emailSchema = new GraphQLSchema({
9995
function createSubscription(
10096
pubsub: SimplePubSub<Email>,
10197
variableValues?: { readonly [variable: string]: unknown },
102-
originalSubscribe: boolean = false,
10398
) {
10499
const document = parse(`
105100
subscription ($priority: Int = 0, $shouldDefer: Boolean = false, $asyncResolver: Boolean = false) {
@@ -145,7 +140,7 @@ function createSubscription(
145140
}),
146141
};
147142

148-
return (originalSubscribe ? subscribe : experimentalSubscribeIncrementally)({
143+
return subscribe({
149144
schema: emailSchema,
150145
document,
151146
rootValue: data,
@@ -703,7 +698,7 @@ describe('Subscription Publish Phase', () => {
703698
});
704699
});
705700

706-
it('produces additional payloads for subscriptions with @defer', async () => {
701+
it('subscribe function returns errors with @defer', async () => {
707702
const pubsub = new SimplePubSub<Email>();
708703
const subscription = await createSubscription(pubsub, {
709704
shouldDefer: true,
@@ -722,155 +717,13 @@ describe('Subscription Publish Phase', () => {
722717
}),
723718
).to.equal(true);
724719

725-
// The previously waited on payload now has a value.
726-
expect(await payload).to.deep.equal({
727-
done: false,
728-
value: {
729-
data: {
730-
importantEmail: {
731-
email: {
732-
733-
subject: 'Alright',
734-
},
735-
},
736-
},
737-
hasNext: true,
738-
},
739-
});
740-
741-
// Wait for the next payload from @defer
742-
expect(await subscription.next()).to.deep.equal({
743-
done: false,
744-
value: {
745-
incremental: [
746-
{
747-
data: {
748-
inbox: {
749-
unread: 1,
750-
total: 2,
751-
},
752-
},
753-
path: ['importantEmail'],
754-
},
755-
],
756-
hasNext: false,
757-
},
758-
});
759-
760-
// Another new email arrives, after all incrementally delivered payloads are received.
761-
expect(
762-
pubsub.emit({
763-
764-
subject: 'Tools',
765-
message: 'I <3 making things',
766-
unread: true,
767-
}),
768-
).to.equal(true);
769-
770-
// The next waited on payload will have a value.
771-
expect(await subscription.next()).to.deep.equal({
772-
done: false,
773-
value: {
774-
data: {
775-
importantEmail: {
776-
email: {
777-
778-
subject: 'Tools',
779-
},
780-
},
781-
},
782-
hasNext: true,
783-
},
784-
});
785-
786-
// Another new email arrives, before the incrementally delivered payloads from the last email was received.
787-
expect(
788-
pubsub.emit({
789-
790-
subject: 'Important',
791-
message: 'Read me please',
792-
unread: true,
793-
}),
794-
).to.equal(true);
795-
796-
// Deferred payload from previous event is received.
797-
expect(await subscription.next()).to.deep.equal({
798-
done: false,
799-
value: {
800-
incremental: [
801-
{
802-
data: {
803-
inbox: {
804-
unread: 2,
805-
total: 3,
806-
},
807-
},
808-
path: ['importantEmail'],
809-
},
810-
],
811-
hasNext: false,
812-
},
813-
});
814-
815-
// Next payload from last event
816-
expect(await subscription.next()).to.deep.equal({
817-
done: false,
818-
value: {
819-
data: {
820-
importantEmail: {
821-
email: {
822-
823-
subject: 'Important',
824-
},
825-
},
826-
},
827-
hasNext: true,
828-
},
829-
});
830-
831-
// The client disconnects before the deferred payload is consumed.
832-
expect(await subscription.return()).to.deep.equal({
833-
done: true,
834-
value: undefined,
835-
});
836-
837-
// Awaiting a subscription after closing it results in completed results.
838-
expect(await subscription.next()).to.deep.equal({
839-
done: true,
840-
value: undefined,
841-
});
842-
});
843-
844-
it('original subscribe function returns errors with @defer', async () => {
845-
const pubsub = new SimplePubSub<Email>();
846-
const subscription = await createSubscription(
847-
pubsub,
848-
{
849-
shouldDefer: true,
850-
},
851-
true,
852-
);
853-
assert(isAsyncIterable(subscription));
854-
// Wait for the next subscription payload.
855-
const payload = subscription.next();
856-
857-
// A new email arrives!
858-
expect(
859-
pubsub.emit({
860-
861-
subject: 'Alright',
862-
message: 'Tests are good',
863-
unread: true,
864-
}),
865-
).to.equal(true);
866-
867720
const errorPayload = {
868721
done: false,
869722
value: {
870723
errors: [
871724
{
872725
message:
873-
'Executing this GraphQL operation would unexpectedly produce multiple payloads (due to @defer or @stream directive)',
726+
'Executing this GraphQL operation would unexpectedly produce multiple payloads (due to @defer or @stream directive). Disable `@defer` or `@stream` by setting the `if` argument to `false`.',
874727
},
875728
],
876729
},
@@ -879,9 +732,6 @@ describe('Subscription Publish Phase', () => {
879732
// The previously waited on payload now has a value.
880733
expectJSON(await payload).toDeepEqual(errorPayload);
881734

882-
// Wait for the next payload from @defer
883-
expectJSON(await subscription.next()).toDeepEqual(errorPayload);
884-
885735
// Another new email arrives, after all incrementally delivered payloads are received.
886736
expect(
887737
pubsub.emit({
@@ -892,12 +742,9 @@ describe('Subscription Publish Phase', () => {
892742
}),
893743
).to.equal(true);
894744

895-
// The next waited on payload will have a value.
896-
expectJSON(await subscription.next()).toDeepEqual(errorPayload);
897745
// The next waited on payload will have a value.
898746
expectJSON(await subscription.next()).toDeepEqual(errorPayload);
899747

900-
// The client disconnects before the deferred payload is consumed.
901748
expectJSON(await subscription.return()).toDeepEqual({
902749
done: true,
903750
value: undefined,

0 commit comments

Comments
 (0)