Use RequestInput as the input for GraphQlService
This commit is contained in:
@@ -32,7 +32,6 @@ import com.jayway.jsonpath.DocumentContext;
|
||||
import com.jayway.jsonpath.JsonPath;
|
||||
import com.jayway.jsonpath.PathNotFoundException;
|
||||
import com.jayway.jsonpath.TypeRef;
|
||||
import graphql.ExecutionInput;
|
||||
import graphql.ExecutionResult;
|
||||
import graphql.GraphQLError;
|
||||
import org.reactivestreams.Publisher;
|
||||
@@ -217,8 +216,7 @@ class DefaultGraphQlTester implements GraphQlTester {
|
||||
}
|
||||
|
||||
protected ExecutionResult executeInternal(RequestInput input) {
|
||||
ExecutionInput executionInput = input.toExecutionInput();
|
||||
ExecutionResult result = this.graphQlService.execute(executionInput).block(responseTimeout());
|
||||
ExecutionResult result = this.graphQlService.execute(input).block(responseTimeout());
|
||||
Assert.notNull(result, "Expected ExecutionResult");
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -24,7 +24,6 @@ import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import graphql.ExecutionInput;
|
||||
import graphql.ExecutionResult;
|
||||
import graphql.ExecutionResultImpl;
|
||||
import graphql.GraphQLError;
|
||||
@@ -36,6 +35,7 @@ import reactor.core.publisher.Mono;
|
||||
|
||||
import org.springframework.core.ParameterizedTypeReference;
|
||||
import org.springframework.graphql.GraphQlService;
|
||||
import org.springframework.graphql.RequestInput;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
@@ -62,7 +62,7 @@ public class GraphQlTesterTests {
|
||||
|
||||
private final GraphQlTester graphQlTester = GraphQlTester.create(this.service);
|
||||
|
||||
private final ArgumentCaptor<ExecutionInput> inputCaptor = ArgumentCaptor.forClass(ExecutionInput.class);
|
||||
private final ArgumentCaptor<RequestInput> inputCaptor = ArgumentCaptor.forClass(RequestInput.class);
|
||||
|
||||
|
||||
@Test
|
||||
@@ -185,7 +185,7 @@ public class GraphQlTesterTests {
|
||||
|
||||
spec.path("hero").entity(MovieCharacter.class).isEqualTo(MovieCharacter.create("R2-D2"));
|
||||
|
||||
ExecutionInput input = this.inputCaptor.getValue();
|
||||
RequestInput input = this.inputCaptor.getValue();
|
||||
assertThat(input.getQuery()).contains(query);
|
||||
assertThat(input.getOperationName()).isEqualTo("HeroNameAndFriends");
|
||||
assertThat(input.getVariables()).hasSize(2);
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
package org.springframework.graphql;
|
||||
|
||||
import graphql.ExecutionInput;
|
||||
import graphql.ExecutionResult;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
@@ -31,9 +30,9 @@ public interface GraphQlService {
|
||||
|
||||
/**
|
||||
* Perform the operation and return the result.
|
||||
* @param input the input for the {@link graphql.GraphQL} invocation
|
||||
* @param input container for the GraphQL request input
|
||||
* @return the execution result
|
||||
*/
|
||||
Mono<ExecutionResult> execute(ExecutionInput input);
|
||||
Mono<ExecutionResult> execute(RequestInput input);
|
||||
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ import graphql.GraphQL;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import org.springframework.graphql.GraphQlService;
|
||||
import org.springframework.graphql.RequestInput;
|
||||
|
||||
/**
|
||||
* Implementation of {@link GraphQlService} that performs GraphQL request execution
|
||||
@@ -39,11 +40,12 @@ public class ExecutionGraphQlService implements GraphQlService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<ExecutionResult> execute(ExecutionInput input) {
|
||||
public Mono<ExecutionResult> execute(RequestInput input) {
|
||||
ExecutionInput executionInput = input.toExecutionInput();
|
||||
GraphQL graphQl = this.graphQlSource.graphQl();
|
||||
return Mono.deferContextual((contextView) -> {
|
||||
ContextManager.setReactorContext(contextView, input);
|
||||
return Mono.fromFuture(graphQl.executeAsync(input));
|
||||
ContextManager.setReactorContext(contextView, executionInput);
|
||||
return Mono.fromFuture(graphQl.executeAsync(executionInput));
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -21,7 +21,6 @@ import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import graphql.ExecutionInput;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import org.springframework.graphql.GraphQlService;
|
||||
@@ -81,13 +80,11 @@ class DefaultWebGraphQlHandlerBuilder implements WebGraphQlHandler.Builder {
|
||||
|
||||
@Override
|
||||
public WebGraphQlHandler build() {
|
||||
List<WebInterceptor> interceptorsToUse = (this.interceptors != null) ? this.interceptors
|
||||
: Collections.emptyList();
|
||||
List<WebInterceptor> interceptorsToUse =
|
||||
(this.interceptors != null) ? this.interceptors : Collections.emptyList();
|
||||
|
||||
WebGraphQlHandler targetHandler = (webInput) -> {
|
||||
ExecutionInput executionInput = webInput.toExecutionInput();
|
||||
return this.service.execute(executionInput).map((result) -> new WebOutput(webInput, result));
|
||||
};
|
||||
WebGraphQlHandler targetHandler = (webInput) ->
|
||||
this.service.execute(webInput).map((result) -> new WebOutput(webInput, result));
|
||||
|
||||
// @formatter:off
|
||||
WebGraphQlHandler interceptionChain = interceptorsToUse.stream()
|
||||
|
||||
@@ -20,6 +20,7 @@ import java.net.URI;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.util.function.Function;
|
||||
|
||||
import graphql.ExecutionResult;
|
||||
import graphql.ExecutionResultImpl;
|
||||
@@ -58,8 +59,11 @@ public class WebInterceptorTests {
|
||||
|
||||
@Test
|
||||
void responseHeader() {
|
||||
Function<WebOutput, WebOutput> headerFunction = (output) ->
|
||||
output.transform((builder) -> builder.responseHeader("testHeader", "testValue"));
|
||||
|
||||
WebGraphQlHandler handler = WebGraphQlHandler.builder((input) -> emptyExecutionResult())
|
||||
.interceptor((input, next) -> next.handle(input).map((output) -> output.transform((builder) -> builder.responseHeader("testHeader", "testValue"))))
|
||||
.interceptor((input, next) -> next.handle(input).map(headerFunction))
|
||||
.build();
|
||||
|
||||
HttpHeaders headers = handler.handle(webInput).block().getResponseHeaders();
|
||||
@@ -71,9 +75,9 @@ public class WebInterceptorTests {
|
||||
void executionInputCustomization() {
|
||||
AtomicReference<String> actualName = new AtomicReference<>();
|
||||
|
||||
WebGraphQlHandler handler = WebGraphQlHandler.builder(
|
||||
(input) -> {
|
||||
actualName.set(input.getOperationName());
|
||||
WebGraphQlHandler handler = WebGraphQlHandler
|
||||
.builder((input) -> {
|
||||
actualName.set(input.toExecutionInput().getOperationName());
|
||||
return emptyExecutionResult();
|
||||
})
|
||||
.interceptor((webInput, next) -> {
|
||||
|
||||
Reference in New Issue
Block a user