2525import java .util .concurrent .atomic .AtomicBoolean ;
2626import java .util .function .BiConsumer ;
2727
28- import graphql .GraphqlErrorBuilder ;
2928import org .assertj .core .api .InstanceOfAssertFactories ;
3029import org .junit .jupiter .api .Test ;
3130import reactor .core .publisher .Flux ;
3938import org .springframework .core .io .buffer .DefaultDataBufferFactory ;
4039import org .springframework .graphql .GraphQlSetup ;
4140import org .springframework .graphql .execution .ErrorType ;
42- import org .springframework .graphql .execution .SubscriptionExceptionResolver ;
4341import org .springframework .graphql .server .ConsumeOneAndNeverCompleteInterceptor ;
4442import org .springframework .graphql .server .WebGraphQlHandler ;
4543import org .springframework .graphql .server .WebGraphQlInterceptor ;
@@ -313,23 +311,20 @@ void clientCompletion() {
313311
314312 @ Test
315313 void subscriptionErrorPayloadIsArray () {
316- final String GREETING_QUERY = "{" +
314+ String query = "{" +
317315 "\" id\" :\" " + SUBSCRIPTION_ID + "\" ," +
318316 "\" type\" :\" subscribe\" ," +
319- "\" payload\" :{\" query\" : \" " +
320- " subscription TestTypenameSubscription {" +
321- " greeting" +
322- " }\" }" +
317+ "\" payload\" :{\" query\" : \" subscription { greetings }\" }" +
323318 "}" ;
324319
325- String schema = "type Subscription { greeting : String! } type Query { greetingUnused : String! }" ;
320+ String schema = "type Subscription { greetings : String! } type Query { greeting : String! }" ;
326321
327322 TestWebSocketSession session = new TestWebSocketSession (Flux .just (
328323 toWebSocketMessage ("{\" type\" :\" connection_init\" }" ),
329- toWebSocketMessage (GREETING_QUERY )));
324+ toWebSocketMessage (query )));
330325
331326 WebGraphQlHandler webHandler = GraphQlSetup .schemaContent (schema )
332- .subscriptionFetcher ("greeting " , env -> Flux .just ("a" , null , "b" ))
327+ .subscriptionFetcher ("greetings " , env -> Flux .just ("a" , null , "b" ))
333328 .toWebGraphQlHandler ();
334329
335330 new GraphQlWebSocketHandler (webHandler , ServerCodecConfigurer .create (), TIMEOUT )
@@ -342,7 +337,7 @@ void subscriptionErrorPayloadIsArray() {
342337 assertThat (actual .getId ()).isEqualTo (SUBSCRIPTION_ID );
343338 assertThat (actual .resolvedType ()).isEqualTo (GraphQlWebSocketMessageType .NEXT );
344339 assertThat (actual .<Map <String , Object >>getPayload ())
345- .containsEntry ("data" , Collections .singletonMap ("greeting " , "a" ));
340+ .containsEntry ("data" , Collections .singletonMap ("greetings " , "a" ));
346341 })
347342 .consumeNextWith ((message ) -> {
348343 GraphQlWebSocketMessage actual = decode (message );
@@ -358,63 +353,6 @@ void subscriptionErrorPayloadIsArray() {
358353 .verify (TIMEOUT );
359354 }
360355
361- @ Test
362- void subscriptionPublisherExceptionResolved () {
363- final String GREETING_QUERY = "{" +
364- "\" id\" :\" " + SUBSCRIPTION_ID + "\" ," +
365- "\" type\" :\" subscribe\" ," +
366- "\" payload\" :{\" query\" : \" " +
367- " subscription TestTypenameSubscription {" +
368- " greeting" +
369- " }\" }" +
370- "}" ;
371-
372- String schema = "type Subscription { greeting: String! } type Query { greetingUnused: String! }" ;
373-
374- TestWebSocketSession session = new TestWebSocketSession (Flux .just (
375- toWebSocketMessage ("{\" type\" :\" connection_init\" }" ),
376- toWebSocketMessage (GREETING_QUERY )));
377-
378- WebGraphQlHandler webHandler = GraphQlSetup .schemaContent (schema )
379- .subscriptionFetcher ("greeting" , env ->
380- Flux .create (emitter -> {
381- emitter .next ("a" );
382- emitter .error (new RuntimeException ("Test Exception" ));
383- emitter .next ("b" );
384- }))
385- .subscriptionExceptionResolvers (SubscriptionExceptionResolver .forSingleError (exception ->
386- GraphqlErrorBuilder .newError ()
387- .message ("Error: " + exception .getMessage ())
388- .errorType (ErrorType .BAD_REQUEST )
389- .build ()))
390- .toWebGraphQlHandler ();
391-
392- new GraphQlWebSocketHandler (webHandler , ServerCodecConfigurer .create (), TIMEOUT )
393- .handle (session ).block (TIMEOUT );
394-
395- StepVerifier .create (session .getOutput ())
396- .consumeNextWith ((message ) -> assertMessageType (message , GraphQlWebSocketMessageType .CONNECTION_ACK ))
397- .consumeNextWith ((message ) -> {
398- GraphQlWebSocketMessage actual = decode (message );
399- assertThat (actual .getId ()).isEqualTo (SUBSCRIPTION_ID );
400- assertThat (actual .resolvedType ()).isEqualTo (GraphQlWebSocketMessageType .NEXT );
401- assertThat (actual .<Map <String , Object >>getPayload ())
402- .containsEntry ("data" , Collections .singletonMap ("greeting" , "a" ));
403- })
404- .consumeNextWith ((message ) -> {
405- GraphQlWebSocketMessage actual = decode (message );
406- assertThat (actual .getId ()).isEqualTo (SUBSCRIPTION_ID );
407- assertThat (actual .resolvedType ()).isEqualTo (GraphQlWebSocketMessageType .ERROR );
408- List <Map <String , Object >> errors = actual .getPayload ();
409- assertThat (errors ).hasSize (1 );
410- assertThat (errors .get (0 )).containsEntry ("message" , "Error: Test Exception" );
411- assertThat (errors .get (0 )).containsEntry ("extensions" ,
412- Collections .singletonMap ("classification" , ErrorType .BAD_REQUEST .name ()));
413- })
414- .expectComplete ()
415- .verify (TIMEOUT );
416- }
417-
418356 private TestWebSocketSession handle (Flux <WebSocketMessage > input , WebGraphQlInterceptor ... interceptors ) {
419357 GraphQlWebSocketHandler handler = new GraphQlWebSocketHandler (
420358 initHandler (interceptors ),
0 commit comments