@@ -576,11 +576,15 @@ describe('connection edge mutations', () => {
576
576
let source ;
577
577
let store ;
578
578
let AppendCommentMutation ;
579
+ let AppendCommentsMutation ;
579
580
let PrependCommentMutation ;
581
+ let PrependCommentsMutation ;
580
582
let DeleteCommentMutation ;
581
583
let DeleteCommentsMutation ;
582
584
let appendOperation ;
585
+ let appendMultipleOperation ;
583
586
let prependOperation ;
587
+ let prependMultipleOperation ;
584
588
let deleteOperation ;
585
589
let deletePluralOperation ;
586
590
const clientID =
@@ -594,7 +598,9 @@ describe('connection edge mutations', () => {
594
598
( {
595
599
FeedbackQuery : query ,
596
600
AppendCommentMutation,
601
+ AppendCommentsMutation,
597
602
PrependCommentMutation,
603
+ PrependCommentsMutation,
598
604
DeleteCommentMutation,
599
605
DeleteCommentsMutation,
600
606
} = generateAndCompile ( `
@@ -606,7 +612,9 @@ describe('connection edge mutations', () => {
606
612
) {
607
613
__id
608
614
edges {
615
+ __typename
609
616
node {
617
+ __typename
610
618
id
611
619
}
612
620
}
@@ -628,6 +636,20 @@ describe('connection edge mutations', () => {
628
636
}
629
637
}
630
638
639
+ mutation AppendCommentsMutation(
640
+ $connections: [ID!]!
641
+ $input: CommentsCreateInput
642
+ ) {
643
+ commentsCreate(input: $input) {
644
+ feedbackCommentEdges @appendEdge(connections: $connections) {
645
+ cursor
646
+ node {
647
+ id
648
+ }
649
+ }
650
+ }
651
+ }
652
+
631
653
mutation PrependCommentMutation(
632
654
$connections: [ID!]!
633
655
$input: CommentCreateInput
@@ -642,6 +664,20 @@ describe('connection edge mutations', () => {
642
664
}
643
665
}
644
666
667
+ mutation PrependCommentsMutation(
668
+ $connections: [ID!]!
669
+ $input: CommentsCreateInput
670
+ ) {
671
+ commentsCreate(input: $input) {
672
+ feedbackCommentEdges @prependEdge(connections: $connections) {
673
+ cursor
674
+ node {
675
+ id
676
+ }
677
+ }
678
+ }
679
+ }
680
+
645
681
mutation DeleteCommentMutation(
646
682
$connections: [ID!]!
647
683
$input: CommentDeleteInput
@@ -668,10 +704,24 @@ describe('connection edge mutations', () => {
668
704
connections : [ clientID ] ,
669
705
input : { } ,
670
706
} ) ;
707
+ appendMultipleOperation = createOperationDescriptor (
708
+ AppendCommentsMutation ,
709
+ {
710
+ connections : [ clientID ] ,
711
+ input : { } ,
712
+ } ,
713
+ ) ;
671
714
prependOperation = createOperationDescriptor ( PrependCommentMutation , {
672
715
connections : [ clientID ] ,
673
716
input : { } ,
674
717
} ) ;
718
+ prependMultipleOperation = createOperationDescriptor (
719
+ PrependCommentsMutation ,
720
+ {
721
+ connections : [ clientID ] ,
722
+ input : { } ,
723
+ } ,
724
+ ) ;
675
725
deleteOperation = createOperationDescriptor ( DeleteCommentMutation , {
676
726
connections : [ clientID ] ,
677
727
input : { } ,
@@ -705,13 +755,15 @@ describe('connection edge mutations', () => {
705
755
comments : {
706
756
edges : [
707
757
{
758
+ __typename : 'CommentsEdge' ,
708
759
cursor : 'cursor-1' ,
709
760
node : {
710
761
__typename : 'Comment' ,
711
762
id : 'node-1' ,
712
763
} ,
713
764
} ,
714
765
{
766
+ __typename : 'CommentsEdge' ,
715
767
cursor : 'cursor-2' ,
716
768
node : {
717
769
__typename : 'Comment' ,
@@ -735,13 +787,15 @@ describe('connection edge mutations', () => {
735
787
__id : clientID ,
736
788
edges : [
737
789
{
790
+ __typename : 'CommentsEdge' ,
738
791
cursor : 'cursor-1' ,
739
792
node : {
740
793
__typename : 'Comment' ,
741
794
id : 'node-1' ,
742
795
} ,
743
796
} ,
744
797
{
798
+ __typename : 'CommentsEdge' ,
745
799
cursor : 'cursor-2' ,
746
800
node : {
747
801
__typename : 'Comment' ,
@@ -795,20 +849,23 @@ describe('connection edge mutations', () => {
795
849
// $FlowExpectedError[incompatible-use]
796
850
expect ( callback . mock . calls [ 0 ] [ 0 ] . data . node . comments . edges ) . toEqual ( [
797
851
{
852
+ __typename : 'CommentsEdge' ,
798
853
cursor : 'cursor-1' ,
799
854
node : {
800
855
__typename : 'Comment' ,
801
856
id : 'node-1' ,
802
857
} ,
803
858
} ,
804
859
{
860
+ __typename : 'CommentsEdge' ,
805
861
cursor : 'cursor-2' ,
806
862
node : {
807
863
__typename : 'Comment' ,
808
864
id : 'node-2' ,
809
865
} ,
810
866
} ,
811
867
{
868
+ __typename : 'CommentsEdge' ,
812
869
cursor : 'cursor-append' ,
813
870
node : {
814
871
__typename : 'Comment' ,
@@ -842,27 +899,31 @@ describe('connection edge mutations', () => {
842
899
// $FlowExpectedError[incompatible-use]
843
900
expect ( callback . mock . calls [ 0 ] [ 0 ] . data . node . comments . edges ) . toEqual ( [
844
901
{
902
+ __typename : 'CommentsEdge' ,
845
903
cursor : 'cursor-prepend' ,
846
904
node : {
847
905
__typename : 'Comment' ,
848
906
id : 'node-prepend' ,
849
907
} ,
850
908
} ,
851
909
{
910
+ __typename : 'CommentsEdge' ,
852
911
cursor : 'cursor-1' ,
853
912
node : {
854
913
__typename : 'Comment' ,
855
914
id : 'node-1' ,
856
915
} ,
857
916
} ,
858
917
{
918
+ __typename : 'CommentsEdge' ,
859
919
cursor : 'cursor-2' ,
860
920
node : {
861
921
__typename : 'Comment' ,
862
922
id : 'node-2' ,
863
923
} ,
864
924
} ,
865
925
{
926
+ __typename : 'CommentsEdge' ,
866
927
cursor : 'cursor-append' ,
867
928
node : {
868
929
__typename : 'Comment' ,
@@ -872,6 +933,169 @@ describe('connection edge mutations', () => {
872
933
] ) ;
873
934
} ) ;
874
935
936
+ it ( 'commits the mutation and inserts multiple comment edges into the connection' , ( ) => {
937
+ const snapshot = environment . lookup ( operation . fragment ) ;
938
+ const callback = jest . fn ( ) ;
939
+ environment . subscribe ( snapshot , callback ) ;
940
+
941
+ environment
942
+ . executeMutation ( {
943
+ operation : appendMultipleOperation ,
944
+ } )
945
+ . subscribe ( callbacks ) ;
946
+
947
+ callback . mockClear ( ) ;
948
+ subject . next ( {
949
+ data : {
950
+ commentsCreate : {
951
+ feedbackCommentEdges : [
952
+ {
953
+ __typename : 'CommentsEdge' ,
954
+ cursor : 'node-append-1' ,
955
+ node : {
956
+ __typename : 'Comment' ,
957
+ id : 'node-append-1' ,
958
+ } ,
959
+ } ,
960
+ {
961
+ __typename : 'CommentsEdge' ,
962
+ cursor : 'node-append-2' ,
963
+ node : {
964
+ __typename : 'Comment' ,
965
+ id : 'node-append-2' ,
966
+ } ,
967
+ } ,
968
+ ] ,
969
+ } ,
970
+ } ,
971
+ } ) ;
972
+ subject . complete ( ) ;
973
+
974
+ expect ( complete ) . toBeCalled ( ) ;
975
+ expect ( error ) . not . toBeCalled ( ) ;
976
+ expect ( callback . mock . calls . length ) . toBe ( 1 ) ;
977
+ // $FlowExpectedError[incompatible-use]
978
+ expect ( callback . mock . calls [ 0 ] [ 0 ] . data . node . comments . edges ) . toEqual ( [
979
+ {
980
+ __typename : 'CommentsEdge' ,
981
+ cursor : 'cursor-1' ,
982
+ node : {
983
+ __typename : 'Comment' ,
984
+ id : 'node-1' ,
985
+ } ,
986
+ } ,
987
+ {
988
+ __typename : 'CommentsEdge' ,
989
+ cursor : 'cursor-2' ,
990
+ node : {
991
+ __typename : 'Comment' ,
992
+ id : 'node-2' ,
993
+ } ,
994
+ } ,
995
+ {
996
+ __typename : 'CommentsEdge' ,
997
+ cursor : 'node-append-1' ,
998
+ node : {
999
+ __typename : 'Comment' ,
1000
+ id : 'node-append-1' ,
1001
+ } ,
1002
+ } ,
1003
+ {
1004
+ __typename : 'CommentsEdge' ,
1005
+ cursor : 'node-append-2' ,
1006
+ node : {
1007
+ __typename : 'Comment' ,
1008
+ id : 'node-append-2' ,
1009
+ } ,
1010
+ } ,
1011
+ ] ) ;
1012
+
1013
+ environment
1014
+ . executeMutation ( {
1015
+ operation : prependMultipleOperation ,
1016
+ } )
1017
+ . subscribe ( callbacks ) ;
1018
+
1019
+ callback . mockClear ( ) ;
1020
+ subject . next ( {
1021
+ data : {
1022
+ commentsCreate : {
1023
+ feedbackCommentEdges : [
1024
+ {
1025
+ __typename : 'CommentsEdge' ,
1026
+ cursor : 'node-prepend-1' ,
1027
+ node : {
1028
+ __typename : 'Comment' ,
1029
+ id : 'node-prepend-1' ,
1030
+ } ,
1031
+ } ,
1032
+ {
1033
+ __typename : 'CommentsEdge' ,
1034
+ cursor : 'node-prepend-2' ,
1035
+ node : {
1036
+ __typename : 'Comment' ,
1037
+ id : 'node-prepend-2' ,
1038
+ } ,
1039
+ } ,
1040
+ ] ,
1041
+ } ,
1042
+ } ,
1043
+ } ) ;
1044
+ subject . complete ( ) ;
1045
+ expect ( callback . mock . calls . length ) . toBe ( 1 ) ;
1046
+ // $FlowExpectedError[incompatible-use]
1047
+ expect ( callback . mock . calls [ 0 ] [ 0 ] . data . node . comments . edges ) . toEqual ( [
1048
+ {
1049
+ __typename : 'CommentsEdge' ,
1050
+ cursor : 'node-prepend-2' ,
1051
+ node : {
1052
+ __typename : 'Comment' ,
1053
+ id : 'node-prepend-2' ,
1054
+ } ,
1055
+ } ,
1056
+ {
1057
+ __typename : 'CommentsEdge' ,
1058
+ cursor : 'node-prepend-1' ,
1059
+ node : {
1060
+ __typename : 'Comment' ,
1061
+ id : 'node-prepend-1' ,
1062
+ } ,
1063
+ } ,
1064
+ {
1065
+ __typename : 'CommentsEdge' ,
1066
+ cursor : 'cursor-1' ,
1067
+ node : {
1068
+ __typename : 'Comment' ,
1069
+ id : 'node-1' ,
1070
+ } ,
1071
+ } ,
1072
+ {
1073
+ __typename : 'CommentsEdge' ,
1074
+ cursor : 'cursor-2' ,
1075
+ node : {
1076
+ __typename : 'Comment' ,
1077
+ id : 'node-2' ,
1078
+ } ,
1079
+ } ,
1080
+ {
1081
+ __typename : 'CommentsEdge' ,
1082
+ cursor : 'node-append-1' ,
1083
+ node : {
1084
+ __typename : 'Comment' ,
1085
+ id : 'node-append-1' ,
1086
+ } ,
1087
+ } ,
1088
+ {
1089
+ __typename : 'CommentsEdge' ,
1090
+ cursor : 'node-append-2' ,
1091
+ node : {
1092
+ __typename : 'Comment' ,
1093
+ id : 'node-append-2' ,
1094
+ } ,
1095
+ } ,
1096
+ ] ) ;
1097
+ } ) ;
1098
+
875
1099
it ( 'inserts an comment edge during optmistic update, and reverts and inserts new edge when server payload resolves' , ( ) => {
876
1100
const snapshot = environment . lookup ( operation . fragment ) ;
877
1101
const callback = jest . fn ( ) ;
@@ -898,20 +1122,23 @@ describe('connection edge mutations', () => {
898
1122
// $FlowExpectedError[incompatible-use]
899
1123
expect ( callback . mock . calls [ 0 ] [ 0 ] . data . node . comments . edges ) . toEqual ( [
900
1124
{
1125
+ __typename : 'CommentsEdge' ,
901
1126
cursor : 'cursor-1' ,
902
1127
node : {
903
1128
__typename : 'Comment' ,
904
1129
id : 'node-1' ,
905
1130
} ,
906
1131
} ,
907
1132
{
1133
+ __typename : 'CommentsEdge' ,
908
1134
cursor : 'cursor-2' ,
909
1135
node : {
910
1136
__typename : 'Comment' ,
911
1137
id : 'node-2' ,
912
1138
} ,
913
1139
} ,
914
1140
{
1141
+ __typename : 'CommentsEdge' ,
915
1142
cursor : 'cursor-optimistic-append' ,
916
1143
node : {
917
1144
__typename : 'Comment' ,
@@ -942,20 +1169,23 @@ describe('connection edge mutations', () => {
942
1169
// $FlowExpectedError[incompatible-use]
943
1170
expect ( callback . mock . calls [ 0 ] [ 0 ] . data . node . comments . edges ) . toEqual ( [
944
1171
{
1172
+ __typename : 'CommentsEdge' ,
945
1173
cursor : 'cursor-1' ,
946
1174
node : {
947
1175
__typename : 'Comment' ,
948
1176
id : 'node-1' ,
949
1177
} ,
950
1178
} ,
951
1179
{
1180
+ __typename : 'CommentsEdge' ,
952
1181
cursor : 'cursor-2' ,
953
1182
node : {
954
1183
__typename : 'Comment' ,
955
1184
id : 'node-2' ,
956
1185
} ,
957
1186
} ,
958
1187
{
1188
+ __typename : 'CommentsEdge' ,
959
1189
cursor : 'cursor-append' ,
960
1190
node : {
961
1191
__typename : 'Comment' ,
@@ -994,6 +1224,7 @@ describe('connection edge mutations', () => {
994
1224
// $FlowExpectedError[incompatible-use]
995
1225
expect ( callback . mock . calls [ 0 ] [ 0 ] . data . node . comments . edges ) . toEqual ( [
996
1226
{
1227
+ __typename : 'CommentsEdge' ,
997
1228
cursor : 'cursor-2' ,
998
1229
node : {
999
1230
__typename : 'Comment' ,
0 commit comments