Skip to content

Commit 04d6a72

Browse files
committed
Use RequestInput as the input for GraphQlService
1 parent 5b444d0 commit 04d6a72

File tree

6 files changed

+23
-23
lines changed

6 files changed

+23
-23
lines changed

spring-graphql-test/src/main/java/org/springframework/graphql/test/tester/DefaultGraphQlTester.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
import com.jayway.jsonpath.JsonPath;
3333
import com.jayway.jsonpath.PathNotFoundException;
3434
import com.jayway.jsonpath.TypeRef;
35-
import graphql.ExecutionInput;
3635
import graphql.ExecutionResult;
3736
import graphql.GraphQLError;
3837
import org.reactivestreams.Publisher;
@@ -217,8 +216,7 @@ protected GraphQlServiceRequestStrategy(GraphQlService service, GraphQlTesterBui
217216
}
218217

219218
protected ExecutionResult executeInternal(RequestInput input) {
220-
ExecutionInput executionInput = input.toExecutionInput();
221-
ExecutionResult result = this.graphQlService.execute(executionInput).block(responseTimeout());
219+
ExecutionResult result = this.graphQlService.execute(input).block(responseTimeout());
222220
Assert.notNull(result, "Expected ExecutionResult");
223221
return result;
224222
}

spring-graphql-test/src/test/java/org/springframework/graphql/test/tester/GraphQlTesterTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424

2525
import com.fasterxml.jackson.core.type.TypeReference;
2626
import com.fasterxml.jackson.databind.ObjectMapper;
27-
import graphql.ExecutionInput;
2827
import graphql.ExecutionResult;
2928
import graphql.ExecutionResultImpl;
3029
import graphql.GraphQLError;
@@ -36,6 +35,7 @@
3635

3736
import org.springframework.core.ParameterizedTypeReference;
3837
import org.springframework.graphql.GraphQlService;
38+
import org.springframework.graphql.RequestInput;
3939
import org.springframework.lang.Nullable;
4040
import org.springframework.util.CollectionUtils;
4141

@@ -62,7 +62,7 @@ public class GraphQlTesterTests {
6262

6363
private final GraphQlTester graphQlTester = GraphQlTester.create(this.service);
6464

65-
private final ArgumentCaptor<ExecutionInput> inputCaptor = ArgumentCaptor.forClass(ExecutionInput.class);
65+
private final ArgumentCaptor<RequestInput> inputCaptor = ArgumentCaptor.forClass(RequestInput.class);
6666

6767

6868
@Test
@@ -185,7 +185,7 @@ void operationNameAndVariables() throws Exception {
185185

186186
spec.path("hero").entity(MovieCharacter.class).isEqualTo(MovieCharacter.create("R2-D2"));
187187

188-
ExecutionInput input = this.inputCaptor.getValue();
188+
RequestInput input = this.inputCaptor.getValue();
189189
assertThat(input.getQuery()).contains(query);
190190
assertThat(input.getOperationName()).isEqualTo("HeroNameAndFriends");
191191
assertThat(input.getVariables()).hasSize(2);

spring-graphql/src/main/java/org/springframework/graphql/GraphQlService.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
package org.springframework.graphql;
1818

19-
import graphql.ExecutionInput;
2019
import graphql.ExecutionResult;
2120
import reactor.core.publisher.Mono;
2221

@@ -31,9 +30,9 @@ public interface GraphQlService {
3130

3231
/**
3332
* Perform the operation and return the result.
34-
* @param input the input for the {@link graphql.GraphQL} invocation
33+
* @param input container for the GraphQL request input
3534
* @return the execution result
3635
*/
37-
Mono<ExecutionResult> execute(ExecutionInput input);
36+
Mono<ExecutionResult> execute(RequestInput input);
3837

3938
}

spring-graphql/src/main/java/org/springframework/graphql/execution/ExecutionGraphQlService.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import reactor.core.publisher.Mono;
2323

2424
import org.springframework.graphql.GraphQlService;
25+
import org.springframework.graphql.RequestInput;
2526

2627
/**
2728
* Implementation of {@link GraphQlService} that performs GraphQL request execution
@@ -39,11 +40,12 @@ public ExecutionGraphQlService(GraphQlSource graphQlSource) {
3940
}
4041

4142
@Override
42-
public Mono<ExecutionResult> execute(ExecutionInput input) {
43+
public Mono<ExecutionResult> execute(RequestInput input) {
44+
ExecutionInput executionInput = input.toExecutionInput();
4345
GraphQL graphQl = this.graphQlSource.graphQl();
4446
return Mono.deferContextual((contextView) -> {
45-
ContextManager.setReactorContext(contextView, input);
46-
return Mono.fromFuture(graphQl.executeAsync(input));
47+
ContextManager.setReactorContext(contextView, executionInput);
48+
return Mono.fromFuture(graphQl.executeAsync(executionInput));
4749
});
4850
}
4951

spring-graphql/src/main/java/org/springframework/graphql/web/DefaultWebGraphQlHandlerBuilder.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import java.util.Collections;
2222
import java.util.List;
2323

24-
import graphql.ExecutionInput;
2524
import reactor.core.publisher.Mono;
2625

2726
import org.springframework.graphql.GraphQlService;
@@ -81,13 +80,11 @@ public WebGraphQlHandler.Builder threadLocalAccessors(List<ThreadLocalAccessor>
8180

8281
@Override
8382
public WebGraphQlHandler build() {
84-
List<WebInterceptor> interceptorsToUse = (this.interceptors != null) ? this.interceptors
85-
: Collections.emptyList();
83+
List<WebInterceptor> interceptorsToUse =
84+
(this.interceptors != null) ? this.interceptors : Collections.emptyList();
8685

87-
WebGraphQlHandler targetHandler = (webInput) -> {
88-
ExecutionInput executionInput = webInput.toExecutionInput();
89-
return this.service.execute(executionInput).map((result) -> new WebOutput(webInput, result));
90-
};
86+
WebGraphQlHandler targetHandler = (webInput) ->
87+
this.service.execute(webInput).map((result) -> new WebOutput(webInput, result));
9188

9289
// @formatter:off
9390
WebGraphQlHandler interceptionChain = interceptorsToUse.stream()

spring-graphql/src/test/java/org/springframework/graphql/web/WebInterceptorTests.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import java.util.Arrays;
2121
import java.util.Collections;
2222
import java.util.concurrent.atomic.AtomicReference;
23+
import java.util.function.Function;
2324

2425
import graphql.ExecutionResult;
2526
import graphql.ExecutionResultImpl;
@@ -58,8 +59,11 @@ void interceptorOrder() {
5859

5960
@Test
6061
void responseHeader() {
62+
Function<WebOutput, WebOutput> headerFunction = (output) ->
63+
output.transform((builder) -> builder.responseHeader("testHeader", "testValue"));
64+
6165
WebGraphQlHandler handler = WebGraphQlHandler.builder((input) -> emptyExecutionResult())
62-
.interceptor((input, next) -> next.handle(input).map((output) -> output.transform((builder) -> builder.responseHeader("testHeader", "testValue"))))
66+
.interceptor((input, next) -> next.handle(input).map(headerFunction))
6367
.build();
6468

6569
HttpHeaders headers = handler.handle(webInput).block().getResponseHeaders();
@@ -71,9 +75,9 @@ void responseHeader() {
7175
void executionInputCustomization() {
7276
AtomicReference<String> actualName = new AtomicReference<>();
7377

74-
WebGraphQlHandler handler = WebGraphQlHandler.builder(
75-
(input) -> {
76-
actualName.set(input.getOperationName());
78+
WebGraphQlHandler handler = WebGraphQlHandler
79+
.builder((input) -> {
80+
actualName.set(input.toExecutionInput().getOperationName());
7781
return emptyExecutionResult();
7882
})
7983
.interceptor((webInput, next) -> {

0 commit comments

Comments
 (0)