@@ -640,7 +640,7 @@ mod test {
640
640
use juniper:: {
641
641
futures:: sink:: SinkExt ,
642
642
parser:: { ParseError , Spanning , Token } ,
643
- DefaultScalarValue , EmptyMutation , FieldResult , InputValue , RootNode , Value ,
643
+ DefaultScalarValue , EmptyMutation , FieldError , FieldResult , InputValue , RootNode , Value ,
644
644
} ;
645
645
use std:: { convert:: Infallible , io} ;
646
646
@@ -678,6 +678,20 @@ mod test {
678
678
)
679
679
. boxed ( )
680
680
}
681
+
682
+ /// error emits an error once, then never emits anything else.
683
+ async fn error ( context : & Context ) -> BoxStream < ' static , FieldResult < i32 > > {
684
+ stream:: once ( future:: ready ( Err ( FieldError :: new (
685
+ "field error" ,
686
+ Value :: null ( ) ,
687
+ ) ) ) )
688
+ . chain (
689
+ tokio:: time:: delay_for ( Duration :: from_secs ( 10000 ) )
690
+ . map ( |_| unreachable ! ( ) )
691
+ . into_stream ( ) ,
692
+ )
693
+ . boxed ( )
694
+ }
681
695
}
682
696
683
697
type ClientMessage = super :: ClientMessage < DefaultScalarValue > ;
@@ -1009,4 +1023,46 @@ mod test {
1009
1023
conn. next( ) . await . unwrap( )
1010
1024
) ;
1011
1025
}
1026
+
1027
+ #[ tokio:: test]
1028
+ async fn test_subscription_field_error ( ) {
1029
+ let mut conn = Connection :: new (
1030
+ new_test_schema ( ) ,
1031
+ ConnectionConfig :: new ( Context ( 1 ) ) . with_keep_alive_interval ( Duration :: from_secs ( 0 ) ) ,
1032
+ ) ;
1033
+
1034
+ conn. send ( ClientMessage :: ConnectionInit {
1035
+ payload : Variables :: default ( ) ,
1036
+ } )
1037
+ . await
1038
+ . unwrap ( ) ;
1039
+
1040
+ assert_eq ! ( ServerMessage :: ConnectionAck , conn. next( ) . await . unwrap( ) ) ;
1041
+
1042
+ conn. send ( ClientMessage :: Start {
1043
+ id : "foo" . to_string ( ) ,
1044
+ payload : StartPayload {
1045
+ query : "subscription Foo {error}" . to_string ( ) ,
1046
+ variables : Variables :: default ( ) ,
1047
+ operation_name : None ,
1048
+ } ,
1049
+ } )
1050
+ . await
1051
+ . unwrap ( ) ;
1052
+
1053
+ match conn. next ( ) . await . unwrap ( ) {
1054
+ ServerMessage :: Data {
1055
+ id,
1056
+ payload : DataPayload { data, errors } ,
1057
+ } => {
1058
+ assert_eq ! ( id, "foo" ) ;
1059
+ assert_eq ! (
1060
+ data,
1061
+ Value :: Object ( [ ( "error" , Value :: null( ) ) ] . iter( ) . cloned( ) . collect( ) )
1062
+ ) ;
1063
+ assert_eq ! ( errors. len( ) , 1 ) ;
1064
+ }
1065
+ msg @ _ => panic ! ( "expected data, got: {:?}" , msg) ,
1066
+ }
1067
+ }
1012
1068
}
0 commit comments