diff --git a/spring-graphql/src/main/java/org/springframework/graphql/web/webflux/GraphQlWebSocketHandler.java b/spring-graphql/src/main/java/org/springframework/graphql/web/webflux/GraphQlWebSocketHandler.java index b125865f..2befdd55 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/web/webflux/GraphQlWebSocketHandler.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/web/webflux/GraphQlWebSocketHandler.java @@ -245,10 +245,8 @@ public class GraphQlWebSocketHandler implements WebSocketHandler { .message(ex.getMessage()) .build() .toSpecification(); - - // Payload needs to be an array - // see: https://github.com/enisdenjo/graphql-ws/blob/master/docs/interfaces/common.ErrorMessage.md#payload - return Mono.just(encode(session, id, MessageType.ERROR, Collections.singletonList(errorMap))); + return Mono.just(encode( + session, id, MessageType.ERROR, Collections.singletonList(errorMap))); }); } diff --git a/spring-graphql/src/main/java/org/springframework/graphql/web/webmvc/GraphQlWebSocketHandler.java b/spring-graphql/src/main/java/org/springframework/graphql/web/webmvc/GraphQlWebSocketHandler.java index 63113783..e6478f38 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/web/webmvc/GraphQlWebSocketHandler.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/web/webmvc/GraphQlWebSocketHandler.java @@ -257,12 +257,13 @@ public class GraphQlWebSocketHandler extends TextWebSocketHandler implements Sub } ErrorType errorType = ErrorType.DataFetchingException; String message = ex.getMessage(); - Map errorMap = GraphqlErrorBuilder.newError().errorType(errorType).message(message).build() + Map errorMap = GraphqlErrorBuilder.newError() + .errorType(errorType) + .message(message) + .build() .toSpecification(); - - // Payload needs to be an array - // see: https://github.com/enisdenjo/graphql-ws/blob/master/docs/interfaces/common.ErrorMessage.md#payload - return Mono.just(encode(id, MessageType.ERROR, Collections.singletonList(errorMap))); + return Mono.just(encode( + id, MessageType.ERROR, Collections.singletonList(errorMap))); }); } diff --git a/spring-graphql/src/test/java/org/springframework/graphql/web/webflux/GraphQlWebSocketHandlerTests.java b/spring-graphql/src/test/java/org/springframework/graphql/web/webflux/GraphQlWebSocketHandlerTests.java index 5bfc3e93..d77d3691 100644 --- a/spring-graphql/src/test/java/org/springframework/graphql/web/webflux/GraphQlWebSocketHandlerTests.java +++ b/spring-graphql/src/test/java/org/springframework/graphql/web/webflux/GraphQlWebSocketHandlerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2021 the original author or authors. + * Copyright 2002-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -248,7 +248,7 @@ public class GraphQlWebSocketHandlerTests extends WebSocketHandlerTestSupport { } @Test - void errorMessagePayloadIsCorrectArray() { + void errorMessagePayloadIsArray() { final String GREETING_QUERY = "{" + "\"id\":\"" + SUBSCRIPTION_ID + "\"," + "\"type\":\"subscribe\"," + @@ -258,9 +258,9 @@ public class GraphQlWebSocketHandlerTests extends WebSocketHandlerTestSupport { " }\"}" + "}"; - WebGraphQlHandler initHandler = GraphQlSetup.schemaContent("" + - "type Subscription { greeting: String! }" + - "type Query { greetingUnused: String! }") + String schema = "type Subscription { greeting: String! } type Query { greetingUnused: String! }"; + + WebGraphQlHandler initHandler = GraphQlSetup.schemaContent(schema) .subscriptionFetcher("greeting", env -> Flux.just("a", null, "b")) .webInterceptor() .toWebGraphQlHandler(); diff --git a/spring-graphql/src/test/java/org/springframework/graphql/web/webmvc/GraphQlWebSocketHandlerTests.java b/spring-graphql/src/test/java/org/springframework/graphql/web/webmvc/GraphQlWebSocketHandlerTests.java index fbdc57f1..cf0c3ecd 100644 --- a/spring-graphql/src/test/java/org/springframework/graphql/web/webmvc/GraphQlWebSocketHandlerTests.java +++ b/spring-graphql/src/test/java/org/springframework/graphql/web/webmvc/GraphQlWebSocketHandlerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2021 the original author or authors. + * Copyright 2002-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -263,9 +263,9 @@ public class GraphQlWebSocketHandlerTests extends WebSocketHandlerTestSupport { " }\"}" + "}"; - WebGraphQlHandler initHandler = GraphQlSetup.schemaContent("" + - "type Subscription { greeting: String! }" + - "type Query { greetingUnused: String! }") + String schema = "type Subscription { greeting: String! }type Query { greetingUnused: String! }"; + + WebGraphQlHandler initHandler = GraphQlSetup.schemaContent(schema) .subscriptionFetcher("greeting", env -> Flux.just("a", null, "b")) .webInterceptor() .toWebGraphQlHandler();