Skip to content

Commit 67711f7

Browse files
committed
Rename Web[Input|Output] to WebGraphQl[Request|Response]
See gh-332
1 parent 182e9e6 commit 67711f7

27 files changed

+295
-279
lines changed

spring-graphql-docs/src/docs/asciidoc/index.adoc

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -130,12 +130,12 @@ transformation of the `graphql.ExecutionInput`:
130130
class MyInterceptor implements WebInterceptor {
131131
132132
@Override
133-
public Mono<WebOutput> intercept(WebInput webInput, WebInterceptorChain chain) {
134-
webInput.configureExecutionInput((executionInput, builder) -> {
133+
public Mono<WebGraphQlResponse> intercept(WebGraphQlRequest request, WebInterceptorChain chain) {
134+
request.configureExecutionInput((executionInput, builder) -> {
135135
Map<String, Object> map = ... ;
136136
return builder.extensions(map).build();
137137
});
138-
return chain.next(webInput);
138+
return chain.next(request);
139139
}
140140
}
141141
----
@@ -148,12 +148,12 @@ the `graphql.ExecutionResult`:
148148
class MyInterceptor implements WebInterceptor {
149149
150150
@Override
151-
public Mono<WebOutput> intercept(WebInput webInput, WebInterceptorChain chain) {
152-
return chain.next(webInput)
153-
.map(webOutput -> {
154-
Object data = webOutput.getData();
151+
public Mono<WebGraphQlResponse> intercept(WebGraphQlRequest request, WebInterceptorChain chain) {
152+
return chain.next(request)
153+
.map(response -> {
154+
Object data = response.getData();
155155
Object updatedData = ... ;
156-
return webOutput.transform(builder -> builder.data(updatedData));
156+
return response.transform(builder -> builder.data(updatedData));
157157
});
158158
}
159159
}

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

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,14 @@
1818

1919

2020
import java.net.URI;
21+
import java.util.Map;
2122

2223
import reactor.core.publisher.Mono;
2324

2425
import org.springframework.graphql.ExecutionGraphQlRequest;
2526
import org.springframework.graphql.ExecutionGraphQlResponse;
26-
import org.springframework.graphql.GraphQlRequest;
2727
import org.springframework.graphql.web.WebGraphQlHandler;
28-
import org.springframework.graphql.web.WebInput;
29-
import org.springframework.graphql.web.WebOutput;
28+
import org.springframework.graphql.web.WebGraphQlRequest;
3029
import org.springframework.http.HttpHeaders;
3130
import org.springframework.http.codec.CodecConfigurer;
3231
import org.springframework.lang.Nullable;
@@ -77,9 +76,15 @@ public CodecConfigurer getCodecConfigurer() {
7776

7877

7978
@Override
80-
protected Mono<ExecutionGraphQlResponse> executeInternal(ExecutionGraphQlRequest request) {
81-
WebInput input = new WebInput(this.url, this.headers, request.toMap(), idGenerator.generateId().toString(), null);
82-
return this.graphQlHandler.handleRequest(input).cast(ExecutionGraphQlResponse.class);
79+
protected Mono<ExecutionGraphQlResponse> executeInternal(ExecutionGraphQlRequest executionRequest) {
80+
81+
String id = idGenerator.generateId().toString();
82+
Map<String, Object> body = executionRequest.toMap();
83+
84+
WebGraphQlRequest webExecutionRequest =
85+
new WebGraphQlRequest(this.url, this.headers, body, id, null);
86+
87+
return this.graphQlHandler.handleRequest(webExecutionRequest).cast(ExecutionGraphQlResponse.class);
8388
}
8489

8590
}

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

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@
3737
import org.springframework.graphql.ExecutionGraphQlResponse;
3838
import org.springframework.graphql.support.DefaultExecutionGraphQlResponse;
3939
import org.springframework.graphql.support.DocumentSource;
40+
import org.springframework.graphql.web.WebGraphQlRequest;
4041
import org.springframework.graphql.web.TestWebSocketClient;
4142
import org.springframework.graphql.web.TestWebSocketConnection;
4243
import org.springframework.graphql.web.WebGraphQlHandler;
43-
import org.springframework.graphql.web.WebInput;
4444
import org.springframework.graphql.web.WebInterceptor;
4545
import org.springframework.graphql.web.webflux.GraphQlHttpHandler;
4646
import org.springframework.graphql.web.webflux.GraphQlWebSocketHandler;
@@ -60,8 +60,8 @@
6060

6161
/**
6262
* Tests for the builders of Web {@code GraphQlTester} extensions, using a
63-
* {@link WebInterceptor} to capture the WebInput on the server side, and
64-
* optionally returning a mock response, or an empty response.
63+
* {@link WebInterceptor} to capture the WebGraphQlRequest on the server side,
64+
* and optionally returning a mock response, or an empty response.
6565
*
6666
* <ul>
6767
* <li>{@link HttpGraphQlTester} via {@link WebTestClient} to {@link GraphQlHttpHandler}
@@ -95,24 +95,24 @@ void mutateUrlHeaders(TesterBuilderSetup builderSetup) {
9595
WebGraphQlTester tester = builder.build();
9696
tester.document(DOCUMENT).execute();
9797

98-
WebInput input = builderSetup.getWebInput();
99-
assertThat(input.getUri().toString()).isEqualTo(url);
100-
assertThat(input.getHeaders().get("h")).containsExactly("one");
98+
WebGraphQlRequest request = builderSetup.getWebGraphQlRequest();
99+
assertThat(request.getUri().toString()).isEqualTo(url);
100+
assertThat(request.getHeaders().get("h")).containsExactly("one");
101101

102102
// Mutate to add header value
103103
builder = tester.mutate().headers(headers -> headers.add("h", "two"));
104104
tester = builder.build();
105105
tester.document(DOCUMENT).execute();
106-
assertThat(builderSetup.getWebInput().getHeaders().get("h")).containsExactly("one", "two");
106+
assertThat(builderSetup.getWebGraphQlRequest().getHeaders().get("h")).containsExactly("one", "two");
107107

108108
// Mutate to replace header
109109
builder = tester.mutate().header("h", "three", "four");
110110
tester = builder.build();
111111
tester.document(DOCUMENT).execute();
112112

113-
input = builderSetup.getWebInput();
114-
assertThat(input.getUri().toString()).isEqualTo(url);
115-
assertThat(input.getHeaders().get("h")).containsExactly("three", "four");
113+
request = builderSetup.getWebGraphQlRequest();
114+
assertThat(request.getUri().toString()).isEqualTo(url);
115+
assertThat(request.getHeaders().get("h")).containsExactly("three", "four");
116116
}
117117

118118
@Test
@@ -125,23 +125,23 @@ void mutateWebTestClientViaConsumer() {
125125

126126
HttpGraphQlTester tester = builder.build();
127127
tester.document(DOCUMENT).execute();
128-
assertThat(testerSetup.getWebInput().getHeaders().get("h")).containsExactly("one");
128+
assertThat(testerSetup.getWebGraphQlRequest().getHeaders().get("h")).containsExactly("one");
129129

130130
// Mutate to add header value
131131
HttpGraphQlTester.Builder<?> builder2 = tester.mutate()
132132
.webTestClient(testClientBuilder -> testClientBuilder.defaultHeaders(h -> h.add("h", "two")));
133133

134134
tester = builder2.build();
135135
tester.document(DOCUMENT).execute();
136-
assertThat(testerSetup.getWebInput().getHeaders().get("h")).containsExactly("one", "two");
136+
assertThat(testerSetup.getWebGraphQlRequest().getHeaders().get("h")).containsExactly("one", "two");
137137

138138
// Mutate to replace header
139139
HttpGraphQlTester.Builder<?> builder3 = tester.mutate()
140140
.webTestClient(testClientBuilder -> testClientBuilder.defaultHeader("h", "three"));
141141

142142
tester = builder3.build();
143143
tester.document(DOCUMENT).execute();
144-
assertThat(testerSetup.getWebInput().getHeaders().get("h")).containsExactly("three");
144+
assertThat(testerSetup.getWebGraphQlRequest().getHeaders().get("h")).containsExactly("three");
145145
}
146146

147147
@ParameterizedTest
@@ -156,14 +156,14 @@ void mutateDocumentSource(TesterBuilderSetup builderSetup) {
156156
WebGraphQlTester tester = builder.build();
157157
tester.documentName("name").execute();
158158

159-
WebInput input = builderSetup.getWebInput();
159+
WebGraphQlRequest input = builderSetup.getWebGraphQlRequest();
160160
assertThat(input.getDocument()).isEqualTo(DOCUMENT);
161161

162162
// Mutate
163163
tester = tester.mutate().build();
164164
tester.documentName("name").execute();
165165

166-
input = builderSetup.getWebInput();
166+
input = builderSetup.getWebGraphQlRequest();
167167
assertThat(input.getDocument()).isEqualTo(DOCUMENT);
168168
}
169169

@@ -202,14 +202,14 @@ private interface TesterBuilderSetup {
202202

203203
void setMockResponse(String document, ExecutionResult result);
204204

205-
WebInput getWebInput();
205+
WebGraphQlRequest getWebGraphQlRequest();
206206

207207
}
208208

209209

210210
private static class WebBuilderSetup implements TesterBuilderSetup {
211211

212-
private WebInput webInput;
212+
private WebGraphQlRequest request;
213213

214214
private final Map<String, ExecutionGraphQlResponse> responses = new HashMap<>();
215215

@@ -235,8 +235,8 @@ protected WebGraphQlHandler webGraphQlHandler() {
235235
return Mono.just(response);
236236
})
237237
.interceptor((input, chain) -> {
238-
this.webInput = input;
239-
return chain.next(webInput);
238+
this.request = input;
239+
return chain.next(request);
240240
})
241241
.build();
242242
}
@@ -248,8 +248,8 @@ public void setMockResponse(String document, ExecutionResult result) {
248248
}
249249

250250
@Override
251-
public WebInput getWebInput() {
252-
return this.webInput;
251+
public WebGraphQlRequest getWebGraphQlRequest() {
252+
return this.request;
253253
}
254254

255255
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ public interface ExecutionGraphQlRequest extends GraphQlRequest {
8282
/**
8383
* Provide a {@code BiFunction} to help initialize the {@link ExecutionInput}
8484
* passed to {@link graphql.GraphQL}. The {@code ExecutionInput} is first
85-
* pre-populated with values from "this" {@code RequestInput}, and is then
86-
* customized with the functions provided here.
85+
* pre-populated with values from "this" {@code ExecutionGraphQlRequest}, and
86+
* is then customized with the functions provided here.
8787
* @param configurer a {@code BiFunction} that accepts the
8888
* {@code ExecutionInput} initialized so far, and a builder to customize it.
8989
*/
@@ -92,8 +92,8 @@ public interface ExecutionGraphQlRequest extends GraphQlRequest {
9292
/**
9393
* Create the {@link ExecutionInput} to pass to {@link graphql.GraphQL}.
9494
* passed to {@link graphql.GraphQL}. The {@code ExecutionInput} is populated
95-
* with values from "this" {@code RequestInput}, and then customized with
96-
* functions provided via {@link #configureExecutionInput(BiFunction)}.
95+
* with values from "this" {@code ExecutionGraphQlRequest}, and then customized
96+
* with functions provided via {@link #configureExecutionInput(BiFunction)}.
9797
* @return the resulting {@code ExecutionInput}
9898
*/
9999
ExecutionInput toExecutionInput();

spring-graphql/src/main/java/org/springframework/graphql/data/query/QuerydslDataFetcher.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -341,8 +341,8 @@ public Builder<T, R> sortBy(Sort sort) {
341341
* {@link #autoRegistrationConfigurer(List, List) auto-registration}.
342342
* For manual registration, you will need to use this method to apply it.
343343
*
344-
* @param customizer to customize GraphQL request input to Querydsl
345-
* Predicate binding with
344+
* @param customizer to customize the binding of the GraphQL request to
345+
* Querydsl Predicate
346346
* @return a new {@link Builder} instance with all previously configured
347347
* options and {@code QuerydslBinderCustomizer} applied
348348
*/

spring-graphql/src/main/java/org/springframework/graphql/support/DefaultExecutionGraphQlRequest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@
3535
* or WebSocket handler) assigned {@link #getId() id} and {@link #getLocale()
3636
* locale} in the addition to the {@code GraphQlRequest} inputs.
3737
*
38-
* <p>{@code RequestInput} supports the initialization of {@link ExecutionInput}
39-
* that is passed to {@link graphql.GraphQL}. You can customize that via
38+
* <p>Supports the initialization of {@link ExecutionInput} that is passed to
39+
* {@link graphql.GraphQL}. You can customize that via
4040
* {@link #configureExecutionInput(BiFunction)}.
4141
*
4242
* @author Rossen Stoyanchev

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,18 +89,18 @@ public WebGraphQlHandler.Builder threadLocalAccessors(List<ThreadLocalAccessor>
8989
public WebGraphQlHandler build() {
9090

9191
WebInterceptorChain endOfChain =
92-
webInput -> this.service.execute(webInput).map(WebOutput::new);
92+
request -> this.service.execute(request).map(WebGraphQlResponse::new);
9393

9494
WebInterceptorChain chain = this.interceptors.stream()
9595
.reduce(WebInterceptor::andThen)
96-
.map(interceptor -> (WebInterceptorChain) (input) -> interceptor.intercept(input, endOfChain))
96+
.map(interceptor -> (WebInterceptorChain) (request) -> interceptor.intercept(request, endOfChain))
9797
.orElse(endOfChain);
9898

9999
return new WebGraphQlHandler() {
100100

101101
@Override
102-
public Mono<WebOutput> handleRequest(WebInput input) {
103-
return chain.next(input)
102+
public Mono<WebGraphQlResponse> handleRequest(WebGraphQlRequest request) {
103+
return chain.next(request)
104104
.contextWrite(context -> {
105105
if (!CollectionUtils.isEmpty(accessors)) {
106106
ThreadLocalAccessor accessor = ThreadLocalAccessor.composite(accessors);

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ public interface WebGraphQlHandler {
3535

3636

3737
/**
38-
* Execute the given request and return the resulting output.
39-
* @param input the GraphQL request input container
40-
* @return the result from execution
38+
* Execute the given request and return the response.
39+
* @param request the request to execute
40+
* @return the response
4141
*/
42-
Mono<WebOutput> handleRequest(WebInput input);
42+
Mono<WebGraphQlResponse> handleRequest(WebGraphQlRequest request);
4343

4444
/**
4545
* Return the single interceptor of type {@link WebSocketInterceptor} among

spring-graphql/src/main/java/org/springframework/graphql/web/WebInput.java renamed to spring-graphql/src/main/java/org/springframework/graphql/web/WebGraphQlRequest.java

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import java.util.Locale;
2121
import java.util.Map;
2222

23+
import org.springframework.graphql.ExecutionGraphQlRequest;
2324
import org.springframework.graphql.support.DefaultExecutionGraphQlRequest;
2425
import org.springframework.http.HttpHeaders;
2526
import org.springframework.lang.Nullable;
@@ -30,41 +31,46 @@
3031
import org.springframework.web.util.UriComponentsBuilder;
3132

3233
/**
33-
* Container for the input of a GraphQL request over HTTP or WebSocket, including
34-
* the URL and HTTP headers, along with the query, operation name, and variables
35-
* from the body of the request. For WebSocket, the URL and HTTP headers are
36-
* those of the WebSocket handshake request.
34+
* {@link org.springframework.graphql.GraphQlRequest} implementation for server
35+
* handling over HTTP or WebSocket. Provides access to the URL and headers of
36+
* the underlying request. For WebSocket, these are the URL and headers of the
37+
* HTTP handshake request.
3738
*
3839
* @author Rossen Stoyanchev
3940
* @since 1.0.0
4041
*/
41-
public class WebInput extends DefaultExecutionGraphQlRequest {
42+
public class WebGraphQlRequest extends DefaultExecutionGraphQlRequest implements ExecutionGraphQlRequest {
4243

4344
private final UriComponents uri;
4445

4546
private final HttpHeaders headers;
4647

48+
4749
/**
4850
* Create an instance.
4951
* @param uri the URL for the HTTP request or WebSocket handshake
5052
* @param headers the HTTP request headers
5153
* @param body the deserialized content of the GraphQL request
5254
* @param id an identifier for the GraphQL request, e.g. a subscription id for
53-
* correlating request and response messages, or it could be an id associated with the
55+
* correlating request and response messages, or it could be an id associated with the
5456
* @param locale the locale from the HTTP request, if any
5557
*/
56-
public WebInput(URI uri, HttpHeaders headers, Map<String, Object> body, String id, @Nullable Locale locale) {
58+
public WebGraphQlRequest(
59+
URI uri, HttpHeaders headers, Map<String, Object> body, String id, @Nullable Locale locale) {
60+
5761
super(getKey("query", body), getKey("operationName", body), getKey("variables", body), id, locale);
62+
5863
Assert.notNull(uri, "URI is required'");
5964
Assert.notNull(headers, "HttpHeaders is required'");
65+
6066
this.uri = UriComponentsBuilder.fromUri(uri).build(true);
6167
this.headers = headers;
6268
}
6369

6470
@SuppressWarnings("unchecked")
6571
private static <T> T getKey(String key, Map<String, Object> body) {
6672
if (key.equals("query") && !StringUtils.hasText((String) body.get(key))) {
67-
throw new ServerWebInputException("No \"query\" in the request input");
73+
throw new ServerWebInputException("No \"query\" in the request document");
6874
}
6975
return (T) body.get(key);
7076
}

0 commit comments

Comments
 (0)