Polish
See gh-183
This commit is contained in:
@@ -86,8 +86,12 @@ public class RequestInput {
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the explicitly assigned request id.
|
||||
* Return an identifier for the request. This id is later propagated
|
||||
* as the {@link ExecutionId} of the execution input.
|
||||
* <p>For web transports, this identifier can be used to correlate
|
||||
* request and response messages on a multiplexed connection.
|
||||
* @return the request id.
|
||||
* @see <a href="https://github.com/enisdenjo/graphql-ws/blob/master/PROTOCOL.md">GraphQL over WebSocket Protocol</a>
|
||||
*/
|
||||
public String getId() {
|
||||
return this.id;
|
||||
|
||||
@@ -25,9 +25,7 @@ import reactor.core.publisher.Mono;
|
||||
import org.springframework.core.ParameterizedTypeReference;
|
||||
import org.springframework.graphql.web.WebGraphQlHandler;
|
||||
import org.springframework.graphql.web.WebInput;
|
||||
import org.springframework.util.AlternativeJdkIdGenerator;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.IdGenerator;
|
||||
import org.springframework.web.reactive.function.server.ServerRequest;
|
||||
import org.springframework.web.reactive.function.server.ServerResponse;
|
||||
|
||||
@@ -48,26 +46,13 @@ public class GraphQlHttpHandler {
|
||||
|
||||
private final WebGraphQlHandler graphQlHandler;
|
||||
|
||||
private final IdGenerator idGenerator;
|
||||
|
||||
/**
|
||||
* Create a new instance.
|
||||
* @param graphQlHandler common handler for GraphQL over HTTP requests
|
||||
*/
|
||||
public GraphQlHttpHandler(WebGraphQlHandler graphQlHandler) {
|
||||
this(graphQlHandler, new AlternativeJdkIdGenerator());
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new instance.
|
||||
* @param graphQlHandler common handler for GraphQL over HTTP requests
|
||||
* @param idGenerator Id generator for requests
|
||||
*/
|
||||
public GraphQlHttpHandler(WebGraphQlHandler graphQlHandler, IdGenerator idGenerator) {
|
||||
Assert.notNull(graphQlHandler, "WebGraphQlHandler is required");
|
||||
Assert.notNull(idGenerator, "IdGenerator is required");
|
||||
this.graphQlHandler = graphQlHandler;
|
||||
this.idGenerator = idGenerator;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -81,7 +66,7 @@ public class GraphQlHttpHandler {
|
||||
WebInput input = new WebInput(
|
||||
request.uri(), request.headers().asHttpHeaders(), body,
|
||||
request.exchange().getLocaleContext().getLocale(),
|
||||
this.idGenerator.generateId().toString());
|
||||
request.exchange().getRequest().getId());
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Executing: " + input);
|
||||
}
|
||||
|
||||
@@ -52,28 +52,17 @@ public class GraphQlHttpHandler {
|
||||
private static final ParameterizedTypeReference<Map<String, Object>> MAP_PARAMETERIZED_TYPE_REF =
|
||||
new ParameterizedTypeReference<Map<String, Object>>() {};
|
||||
|
||||
private final WebGraphQlHandler graphQlHandler;
|
||||
private final IdGenerator idGenerator = new AlternativeJdkIdGenerator();
|
||||
|
||||
private final IdGenerator idGenerator;
|
||||
private final WebGraphQlHandler graphQlHandler;
|
||||
|
||||
/**
|
||||
* Create a new instance.
|
||||
* @param graphQlHandler common handler for GraphQL over HTTP requests
|
||||
*/
|
||||
public GraphQlHttpHandler(WebGraphQlHandler graphQlHandler) {
|
||||
this(graphQlHandler, new AlternativeJdkIdGenerator());
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new instance.
|
||||
* @param graphQlHandler common handler for GraphQL over HTTP requests
|
||||
* @param idGenerator Id generator for requests
|
||||
*/
|
||||
public GraphQlHttpHandler(WebGraphQlHandler graphQlHandler, IdGenerator idGenerator) {
|
||||
Assert.notNull(graphQlHandler, "WebGraphQlHandler is required");
|
||||
Assert.notNull(idGenerator, "IdGenerator is required");
|
||||
this.graphQlHandler = graphQlHandler;
|
||||
this.idGenerator = idGenerator;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -19,7 +19,6 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import com.jayway.jsonpath.DocumentContext;
|
||||
import com.jayway.jsonpath.JsonPath;
|
||||
@@ -39,7 +38,6 @@ import org.springframework.web.reactive.result.view.ViewResolver;
|
||||
import org.springframework.web.server.ServerWebExchange;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatNoException;
|
||||
|
||||
/**
|
||||
* Tests for {@link GraphQlHttpHandler}.
|
||||
@@ -76,7 +74,7 @@ public class GraphQlHttpHandlerTests {
|
||||
|
||||
DocumentContext document = JsonPath.parse(httpResponse.getBodyAsString().block());
|
||||
String id = document.read("data.showId", String.class);
|
||||
assertThatNoException().isThrownBy(() -> UUID.fromString(id));
|
||||
assertThat(id).isEqualTo(httpRequest.getId());
|
||||
}
|
||||
|
||||
private MockServerHttpResponse handleRequest(
|
||||
|
||||
Reference in New Issue
Block a user