@@ -21,11 +21,7 @@ import {
21
21
import { GraphQLSchema } from '../../type/schema.js' ;
22
22
23
23
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' ;
29
25
30
26
import { SimplePubSub } from './simplePubSub.js' ;
31
27
@@ -99,7 +95,6 @@ const emailSchema = new GraphQLSchema({
99
95
function createSubscription (
100
96
pubsub : SimplePubSub < Email > ,
101
97
variableValues ?: { readonly [ variable : string ] : unknown } ,
102
- originalSubscribe : boolean = false ,
103
98
) {
104
99
const document = parse ( `
105
100
subscription ($priority: Int = 0, $shouldDefer: Boolean = false, $asyncResolver: Boolean = false) {
@@ -145,7 +140,7 @@ function createSubscription(
145
140
} ) ,
146
141
} ;
147
142
148
- return ( originalSubscribe ? subscribe : experimentalSubscribeIncrementally ) ( {
143
+ return subscribe ( {
149
144
schema : emailSchema ,
150
145
document,
151
146
rootValue : data ,
@@ -703,7 +698,7 @@ describe('Subscription Publish Phase', () => {
703
698
} ) ;
704
699
} ) ;
705
700
706
- it ( 'produces additional payloads for subscriptions with @defer' , async ( ) => {
701
+ it ( 'subscribe function returns errors with @defer' , async ( ) => {
707
702
const pubsub = new SimplePubSub < Email > ( ) ;
708
703
const subscription = await createSubscription ( pubsub , {
709
704
shouldDefer : true ,
@@ -722,155 +717,13 @@ describe('Subscription Publish Phase', () => {
722
717
} ) ,
723
718
) . to . equal ( true ) ;
724
719
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
-
867
720
const errorPayload = {
868
721
done : false ,
869
722
value : {
870
723
errors : [
871
724
{
872
725
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`. ' ,
874
727
} ,
875
728
] ,
876
729
} ,
@@ -879,9 +732,6 @@ describe('Subscription Publish Phase', () => {
879
732
// The previously waited on payload now has a value.
880
733
expectJSON ( await payload ) . toDeepEqual ( errorPayload ) ;
881
734
882
- // Wait for the next payload from @defer
883
- expectJSON ( await subscription . next ( ) ) . toDeepEqual ( errorPayload ) ;
884
-
885
735
// Another new email arrives, after all incrementally delivered payloads are received.
886
736
expect (
887
737
pubsub . emit ( {
@@ -892,12 +742,9 @@ describe('Subscription Publish Phase', () => {
892
742
} ) ,
893
743
) . to . equal ( true ) ;
894
744
895
- // The next waited on payload will have a value.
896
- expectJSON ( await subscription . next ( ) ) . toDeepEqual ( errorPayload ) ;
897
745
// The next waited on payload will have a value.
898
746
expectJSON ( await subscription . next ( ) ) . toDeepEqual ( errorPayload ) ;
899
747
900
- // The client disconnects before the deferred payload is consumed.
901
748
expectJSON ( await subscription . return ( ) ) . toDeepEqual ( {
902
749
done : true ,
903
750
value : undefined ,
0 commit comments