25
25
import java .util .concurrent .atomic .AtomicBoolean ;
26
26
import java .util .function .BiConsumer ;
27
27
28
- import graphql .GraphqlErrorBuilder ;
29
28
import org .assertj .core .api .InstanceOfAssertFactories ;
30
29
import org .junit .jupiter .api .Test ;
31
30
import reactor .core .publisher .Flux ;
39
38
import org .springframework .core .io .buffer .DefaultDataBufferFactory ;
40
39
import org .springframework .graphql .GraphQlSetup ;
41
40
import org .springframework .graphql .execution .ErrorType ;
42
- import org .springframework .graphql .execution .SubscriptionExceptionResolver ;
43
41
import org .springframework .graphql .server .ConsumeOneAndNeverCompleteInterceptor ;
44
42
import org .springframework .graphql .server .WebGraphQlHandler ;
45
43
import org .springframework .graphql .server .WebGraphQlInterceptor ;
@@ -313,23 +311,20 @@ void clientCompletion() {
313
311
314
312
@ Test
315
313
void subscriptionErrorPayloadIsArray () {
316
- final String GREETING_QUERY = "{" +
314
+ String query = "{" +
317
315
"\" id\" :\" " + SUBSCRIPTION_ID + "\" ," +
318
316
"\" type\" :\" subscribe\" ," +
319
- "\" payload\" :{\" query\" : \" " +
320
- " subscription TestTypenameSubscription {" +
321
- " greeting" +
322
- " }\" }" +
317
+ "\" payload\" :{\" query\" : \" subscription { greetings }\" }" +
323
318
"}" ;
324
319
325
- String schema = "type Subscription { greeting : String! } type Query { greetingUnused : String! }" ;
320
+ String schema = "type Subscription { greetings : String! } type Query { greeting : String! }" ;
326
321
327
322
TestWebSocketSession session = new TestWebSocketSession (Flux .just (
328
323
toWebSocketMessage ("{\" type\" :\" connection_init\" }" ),
329
- toWebSocketMessage (GREETING_QUERY )));
324
+ toWebSocketMessage (query )));
330
325
331
326
WebGraphQlHandler webHandler = GraphQlSetup .schemaContent (schema )
332
- .subscriptionFetcher ("greeting " , env -> Flux .just ("a" , null , "b" ))
327
+ .subscriptionFetcher ("greetings " , env -> Flux .just ("a" , null , "b" ))
333
328
.toWebGraphQlHandler ();
334
329
335
330
new GraphQlWebSocketHandler (webHandler , ServerCodecConfigurer .create (), TIMEOUT )
@@ -342,7 +337,7 @@ void subscriptionErrorPayloadIsArray() {
342
337
assertThat (actual .getId ()).isEqualTo (SUBSCRIPTION_ID );
343
338
assertThat (actual .resolvedType ()).isEqualTo (GraphQlWebSocketMessageType .NEXT );
344
339
assertThat (actual .<Map <String , Object >>getPayload ())
345
- .containsEntry ("data" , Collections .singletonMap ("greeting " , "a" ));
340
+ .containsEntry ("data" , Collections .singletonMap ("greetings " , "a" ));
346
341
})
347
342
.consumeNextWith ((message ) -> {
348
343
GraphQlWebSocketMessage actual = decode (message );
@@ -358,63 +353,6 @@ void subscriptionErrorPayloadIsArray() {
358
353
.verify (TIMEOUT );
359
354
}
360
355
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
-
418
356
private TestWebSocketSession handle (Flux <WebSocketMessage > input , WebGraphQlInterceptor ... interceptors ) {
419
357
GraphQlWebSocketHandler handler = new GraphQlWebSocketHandler (
420
358
initHandler (interceptors ),
0 commit comments