Polishing contribution

Closes gh-203
This commit is contained in:
rstoyanchev
2022-01-17 21:32:58 +00:00
parent 175673d291
commit bc70922ea2
4 changed files with 17 additions and 18 deletions

View File

@@ -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)));
});
}

View File

@@ -257,12 +257,13 @@ public class GraphQlWebSocketHandler extends TextWebSocketHandler implements Sub
}
ErrorType errorType = ErrorType.DataFetchingException;
String message = ex.getMessage();
Map<String, Object> errorMap = GraphqlErrorBuilder.newError().errorType(errorType).message(message).build()
Map<String, Object> 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)));
});
}

View File

@@ -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();

View File

@@ -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();