Skip to content

Commit bc70922

Browse files
committed
Polishing contribution
Closes gh-203
1 parent 175673d commit bc70922

File tree

4 files changed

+17
-18
lines changed

4 files changed

+17
-18
lines changed

spring-graphql/src/main/java/org/springframework/graphql/web/webflux/GraphQlWebSocketHandler.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -245,10 +245,8 @@ private Flux<WebSocketMessage> handleWebOutput(WebSocketSession session, String
245245
.message(ex.getMessage())
246246
.build()
247247
.toSpecification();
248-
249-
// Payload needs to be an array
250-
// see: https://github.com/enisdenjo/graphql-ws/blob/master/docs/interfaces/common.ErrorMessage.md#payload
251-
return Mono.just(encode(session, id, MessageType.ERROR, Collections.singletonList(errorMap)));
248+
return Mono.just(encode(
249+
session, id, MessageType.ERROR, Collections.singletonList(errorMap)));
252250
});
253251
}
254252

spring-graphql/src/main/java/org/springframework/graphql/web/webmvc/GraphQlWebSocketHandler.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -257,12 +257,13 @@ private Flux<TextMessage> handleWebOutput(WebSocketSession session, String id, W
257257
}
258258
ErrorType errorType = ErrorType.DataFetchingException;
259259
String message = ex.getMessage();
260-
Map<String, Object> errorMap = GraphqlErrorBuilder.newError().errorType(errorType).message(message).build()
260+
Map<String, Object> errorMap = GraphqlErrorBuilder.newError()
261+
.errorType(errorType)
262+
.message(message)
263+
.build()
261264
.toSpecification();
262-
263-
// Payload needs to be an array
264-
// see: https://github.com/enisdenjo/graphql-ws/blob/master/docs/interfaces/common.ErrorMessage.md#payload
265-
return Mono.just(encode(id, MessageType.ERROR, Collections.singletonList(errorMap)));
265+
return Mono.just(encode(
266+
id, MessageType.ERROR, Collections.singletonList(errorMap)));
266267
});
267268
}
268269

spring-graphql/src/test/java/org/springframework/graphql/web/webflux/GraphQlWebSocketHandlerTests.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2021 the original author or authors.
2+
* Copyright 2002-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -248,7 +248,7 @@ void clientCompletion() {
248248
}
249249

250250
@Test
251-
void errorMessagePayloadIsCorrectArray() {
251+
void errorMessagePayloadIsArray() {
252252
final String GREETING_QUERY = "{" +
253253
"\"id\":\"" + SUBSCRIPTION_ID + "\"," +
254254
"\"type\":\"subscribe\"," +
@@ -258,9 +258,9 @@ void errorMessagePayloadIsCorrectArray() {
258258
" }\"}" +
259259
"}";
260260

261-
WebGraphQlHandler initHandler = GraphQlSetup.schemaContent("" +
262-
"type Subscription { greeting: String! }" +
263-
"type Query { greetingUnused: String! }")
261+
String schema = "type Subscription { greeting: String! } type Query { greetingUnused: String! }";
262+
263+
WebGraphQlHandler initHandler = GraphQlSetup.schemaContent(schema)
264264
.subscriptionFetcher("greeting", env -> Flux.just("a", null, "b"))
265265
.webInterceptor()
266266
.toWebGraphQlHandler();

spring-graphql/src/test/java/org/springframework/graphql/web/webmvc/GraphQlWebSocketHandlerTests.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2021 the original author or authors.
2+
* Copyright 2002-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -263,9 +263,9 @@ void errorMessagePayloadIsCorrectArray() throws Exception {
263263
" }\"}" +
264264
"}";
265265

266-
WebGraphQlHandler initHandler = GraphQlSetup.schemaContent("" +
267-
"type Subscription { greeting: String! }" +
268-
"type Query { greetingUnused: String! }")
266+
String schema = "type Subscription { greeting: String! }type Query { greetingUnused: String! }";
267+
268+
WebGraphQlHandler initHandler = GraphQlSetup.schemaContent(schema)
269269
.subscriptionFetcher("greeting", env -> Flux.just("a", null, "b"))
270270
.webInterceptor()
271271
.toWebGraphQlHandler();

0 commit comments

Comments
 (0)