Skip to content

Commit dfff400

Browse files
committed
Rename [Web|Socket]Interceptor
Use more qualified names [Web|Socket]GraphQlHandlerInterceptor to differentiate with ClientGraphQlInterceptor and to align with other types in the same package.
1 parent c0f97d3 commit dfff400

File tree

20 files changed

+97
-89
lines changed

20 files changed

+97
-89
lines changed

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

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -118,19 +118,19 @@ The Spring for GraphQL repository contains a WebFlux
118118

119119
<<web-http>> and <<web-websocket>> transport handlers delegate to a common Web
120120
interception chain for request execution. The chain consists of a sequence of
121-
`WebInterceptor` components, followed by a `ExecutionGraphQlService` that invokes
122-
GraphQL Java.
121+
`WebGraphQlHandlerInterceptor` components, followed by a `ExecutionGraphQlService` that
122+
invokes GraphQL Java.
123123

124-
`WebInterceptor` is as a common contract to use in both Spring MVC and WebFlux
125-
applications. Use it to intercept requests, inspect HTTP request headers, or to register a
126-
transformation of the `graphql.ExecutionInput`:
124+
`WebGraphQlHandlerInterceptor` is as a common contract to use in both Spring MVC and
125+
WebFlux applications. Use it to intercept requests, inspect HTTP request headers, or to
126+
register a transformation of the `graphql.ExecutionInput`:
127127

128128
[source,java,indent=0,subs="verbatim,quotes"]
129129
----
130-
class MyInterceptor implements WebInterceptor {
130+
class MyInterceptor implements WebGraphQlHandlerInterceptor {
131131
132132
@Override
133-
public Mono<WebGraphQlResponse> intercept(WebGraphQlRequest request, WebInterceptorChain chain) {
133+
public Mono<WebGraphQlResponse> intercept(WebGraphQlRequest request, Chain chain) {
134134
request.configureExecutionInput((executionInput, builder) -> {
135135
Map<String, Object> map = ... ;
136136
return builder.extensions(map).build();
@@ -140,15 +140,15 @@ class MyInterceptor implements WebInterceptor {
140140
}
141141
----
142142

143-
Use `WebInterceptor` also to intercept responses, add HTTP response headers, or transform
144-
the `graphql.ExecutionResult`:
143+
Use `WebGraphQlHandlerInterceptor` also to intercept responses, add HTTP response headers,
144+
or transform the `graphql.ExecutionResult`:
145145

146146
[source,java,indent=0,subs="verbatim,quotes"]
147147
----
148-
class MyInterceptor implements WebInterceptor {
148+
class MyInterceptor implements WebGraphQlHandlerInterceptor {
149149
150150
@Override
151-
public Mono<WebGraphQlResponse> intercept(WebGraphQlRequest request, WebInterceptorChain chain) {
151+
public Mono<WebGraphQlResponse> intercept(WebGraphQlRequest request, Chain chain) {
152152
return chain.next(request)
153153
.map(response -> {
154154
Object data = response.getData();
@@ -423,7 +423,8 @@ thread and Reactor `Context` from the WebFlux processing pipeline.
423423

424424
A `DataFetcher` and other components invoked by GraphQL Java may not always execute on
425425
the same thread as the Spring MVC handler, for example if an asynchronous
426-
<<web-interception, `WebInterceptor`>> or `DataFetcher` switches to a different thread.
426+
<<web-interception, `WebGraphQlHandlerInterceptor`>> or `DataFetcher` switches to a
427+
different thread.
427428

428429
Spring for GraphQL supports propagating `ThreadLocal` values from the Servlet container
429430
thread to the thread a `DataFetcher` and other components invoked by GraphQL Java to
@@ -467,7 +468,7 @@ Spring MVC application, see the
467468

468469
A <<execution-reactive-datafetcher>> can rely on access to Reactor context that
469470
originates from the WebFlux request handling chain. This includes Reactor context
470-
added by <<web-interception, WebInterceptor>> components.
471+
added by <<web-interception, WebGraphQlHandlerInterceptor>> components.
471472

472473

473474

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,8 @@ a client. However, in some cases it's useful to involve server side transport
197197
handling with given mock transport input.
198198

199199
The `WebGraphQlHandlerTester` extension lets you processes request through the
200-
`WebInterceptor` chain before handing off to `ExecutionGraphQlService` for request execution:
200+
`WebGraphQlHandlerInterceptor` chain before handing off to `ExecutionGraphQlService` for
201+
request execution:
201202

202203
[source,java,indent=0,subs="verbatim,quotes"]
203204
----

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
/**
2727
* Server-side tester, without a client, that executes requests through a
2828
* {@link WebGraphQlHandler}. Similar to {@link GraphQlServiceTester} but also
29-
* adding a web processing layer with a {@code WebInterceptor} chain.
29+
* adding a web processing layer with a {@code WebGraphQlHandlerInterceptor}
30+
* chain.
3031
*
3132
* @author Rossen Stoyanchev
3233
* @since 1.0.0

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
import org.springframework.graphql.web.TestWebSocketClient;
4242
import org.springframework.graphql.web.TestWebSocketConnection;
4343
import org.springframework.graphql.web.WebGraphQlHandler;
44-
import org.springframework.graphql.web.WebInterceptor;
44+
import org.springframework.graphql.web.WebGraphQlHandlerInterceptor;
4545
import org.springframework.graphql.web.webflux.GraphQlHttpHandler;
4646
import org.springframework.graphql.web.webflux.GraphQlWebSocketHandler;
4747
import org.springframework.http.codec.ClientCodecConfigurer;
@@ -60,8 +60,8 @@
6060

6161
/**
6262
* Tests for the builders of Web {@code GraphQlTester} extensions, using a
63-
* {@link WebInterceptor} to capture the WebGraphQlRequest on the server side,
64-
* and optionally returning a mock response, or an empty response.
63+
* {@link WebGraphQlHandlerInterceptor} to capture the WebGraphQlRequest on the
64+
* server side, and optionally returning a mock response, or an empty response.
6565
*
6666
* <ul>
6767
* <li>{@link HttpGraphQlTester} via {@link WebTestClient} to {@link GraphQlHttpHandler}

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ class DefaultWebGraphQlHandlerBuilder implements WebGraphQlHandler.Builder {
3939

4040
private final ExecutionGraphQlService service;
4141

42-
private final List<WebInterceptor> interceptors = new ArrayList<>();
42+
private final List<WebGraphQlHandlerInterceptor> interceptors = new ArrayList<>();
4343

4444
@Nullable
45-
private WebSocketInterceptor webSocketInterceptor;
45+
private WebSocketGraphQlHandlerInterceptor webSocketInterceptor;
4646

4747
@Nullable
4848
private List<ThreadLocalAccessor> accessors;
@@ -55,17 +55,17 @@ class DefaultWebGraphQlHandlerBuilder implements WebGraphQlHandler.Builder {
5555

5656

5757
@Override
58-
public WebGraphQlHandler.Builder interceptor(WebInterceptor... interceptors) {
58+
public WebGraphQlHandler.Builder interceptor(WebGraphQlHandlerInterceptor... interceptors) {
5959
return interceptors(Arrays.asList(interceptors));
6060
}
6161

6262
@Override
63-
public WebGraphQlHandler.Builder interceptors(List<WebInterceptor> interceptors) {
63+
public WebGraphQlHandler.Builder interceptors(List<WebGraphQlHandlerInterceptor> interceptors) {
6464
this.interceptors.addAll(interceptors);
6565
interceptors.forEach(interceptor -> {
66-
if (interceptor instanceof WebSocketInterceptor) {
66+
if (interceptor instanceof WebSocketGraphQlHandlerInterceptor) {
6767
Assert.isNull(this.webSocketInterceptor, "There can be at most 1 WebSocketInterceptor");
68-
this.webSocketInterceptor = (WebSocketInterceptor) interceptor;
68+
this.webSocketInterceptor = (WebSocketGraphQlHandlerInterceptor) interceptor;
6969
}
7070
});
7171
return this;
@@ -88,12 +88,12 @@ public WebGraphQlHandler.Builder threadLocalAccessors(List<ThreadLocalAccessor>
8888
@Override
8989
public WebGraphQlHandler build() {
9090

91-
WebInterceptor.Chain endOfChain =
91+
WebGraphQlHandlerInterceptor.Chain endOfChain =
9292
request -> this.service.execute(request).map(WebGraphQlResponse::new);
9393

94-
WebInterceptor.Chain chain = this.interceptors.stream()
95-
.reduce(WebInterceptor::andThen)
96-
.map(interceptor -> (WebInterceptor.Chain) (request) -> interceptor.intercept(request, endOfChain))
94+
WebGraphQlHandlerInterceptor.Chain chain = this.interceptors.stream()
95+
.reduce(WebGraphQlHandlerInterceptor::andThen)
96+
.map(interceptor -> (WebGraphQlHandlerInterceptor.Chain) (request) -> interceptor.intercept(request, endOfChain))
9797
.orElse(endOfChain);
9898

9999
return new WebGraphQlHandler() {
@@ -111,8 +111,8 @@ public Mono<WebGraphQlResponse> handleRequest(WebGraphQlRequest request) {
111111
}
112112

113113
@Override
114-
public WebSocketInterceptor webSocketInterceptor() {
115-
return (webSocketInterceptor != null ? webSocketInterceptor : new WebSocketInterceptor() {});
114+
public WebSocketGraphQlHandlerInterceptor webSocketInterceptor() {
115+
return (webSocketInterceptor != null ? webSocketInterceptor : new WebSocketGraphQlHandlerInterceptor() {});
116116
}
117117

118118
};

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

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,11 @@ public interface WebGraphQlHandler {
4242
Mono<WebGraphQlResponse> handleRequest(WebGraphQlRequest request);
4343

4444
/**
45-
* Return the single interceptor of type {@link WebSocketInterceptor} among
46-
* all the configured interceptors.
45+
* Return the single interceptor of type
46+
* {@link WebSocketGraphQlHandlerInterceptor} among all the configured
47+
* interceptors.
4748
*/
48-
WebSocketInterceptor webSocketInterceptor();
49+
WebSocketGraphQlHandlerInterceptor webSocketInterceptor();
4950

5051

5152
/**
@@ -61,28 +62,31 @@ static Builder builder(ExecutionGraphQlService graphQlService) {
6162

6263
/**
6364
* Builder for a {@link WebGraphQlHandler} that executes a
64-
* {@link WebInterceptor} chain followed by a {@link ExecutionGraphQlService}.
65+
* {@link WebGraphQlHandlerInterceptor} chain followed by a
66+
* {@link ExecutionGraphQlService}.
6567
*/
6668
interface Builder {
6769

6870
/**
6971
* Configure interceptors to be invoked before the target
7072
* {@code GraphQlService}.
71-
* <p>One of the interceptors can be of type {@link WebSocketInterceptor}
72-
* to handle data from the first {@code ConnectionInit} message expected
73-
* on a GraphQL over WebSocket session, as well as the {@code Complete}
74-
* message expected at the end of a session.
73+
* <p>One of the interceptors can be of type
74+
* {@link WebSocketGraphQlHandlerInterceptor} to handle data from the
75+
* first {@code ConnectionInit} message expected on a GraphQL over
76+
* WebSocket session, as well as the {@code Complete} message expected
77+
* at the end of a session.
7578
* @param interceptors the interceptors to add
7679
* @return this builder
7780
*/
78-
Builder interceptor(WebInterceptor... interceptors);
81+
Builder interceptor(WebGraphQlHandlerInterceptor... interceptors);
7982

8083
/**
81-
* Alternative to {@link #interceptor(WebInterceptor...)} with a List.
84+
* Alternative to {@link #interceptor(WebGraphQlHandlerInterceptor...)}
85+
* with a List.
8286
* @param interceptors the list of interceptors to add
8387
* @return this builder
8488
*/
85-
Builder interceptors(List<WebInterceptor> interceptors);
89+
Builder interceptors(List<WebGraphQlHandlerInterceptor> interceptors);
8690

8791
/**
8892
* Configure accessors for ThreadLocal variables to use to extract

spring-graphql/src/main/java/org/springframework/graphql/web/WebInterceptor.java renamed to spring-graphql/src/main/java/org/springframework/graphql/web/WebGraphQlHandlerInterceptor.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@
3737
*
3838
* @author Rossen Stoyanchev
3939
* @since 1.0.0
40-
* @see WebSocketInterceptor
40+
* @see WebSocketGraphQlHandlerInterceptor
4141
*/
42-
public interface WebInterceptor {
42+
public interface WebGraphQlHandlerInterceptor {
4343

4444
/**
4545
* Intercept a request and delegate to the rest of the chain including other
@@ -51,13 +51,13 @@ public interface WebInterceptor {
5151
Mono<WebGraphQlResponse> intercept(WebGraphQlRequest request, Chain chain);
5252

5353
/**
54-
* Return a new {@link WebInterceptor} that invokes the current interceptor
55-
* first and then the one that is passed in.
54+
* Return a new {@link WebGraphQlHandlerInterceptor} that invokes the current
55+
* interceptor first and then the one that is passed in.
5656
* @param interceptor the interceptor to delegate to after "this"
57-
* @return the new {@code WebInterceptor}
57+
* @return the new {@code WebGraphQlHandlerInterceptor}
5858
*/
59-
default WebInterceptor andThen(WebInterceptor interceptor) {
60-
Assert.notNull(interceptor, "WebInterceptor is required");
59+
default WebGraphQlHandlerInterceptor andThen(WebGraphQlHandlerInterceptor interceptor) {
60+
Assert.notNull(interceptor, "WebGraphQlHandlerInterceptor is required");
6161
return (request, chain) -> {
6262
Chain nextChain = nextRequest -> interceptor.intercept(nextRequest, chain);
6363
return intercept(request, nextChain);

spring-graphql/src/main/java/org/springframework/graphql/web/WebSocketInterceptor.java renamed to spring-graphql/src/main/java/org/springframework/graphql/web/WebSocketGraphQlHandlerInterceptor.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,15 @@
2121

2222

2323
/**
24-
* An extension of {@link WebInterceptor} with additional methods to handle the
25-
* start and end of a WebSocket connection. Only a single interceptor of type
26-
* {@link WebSocketInterceptor} may be declared.
24+
* An extension of {@link WebGraphQlHandlerInterceptor} with additional methods
25+
* to handle the start and end of a WebSocket connection. Only a single
26+
* interceptor of type {@link WebSocketGraphQlHandlerInterceptor} may be
27+
* declared.
2728
*
2829
* @author Rossen Stoyanchev
2930
* @since 1.0.0
3031
*/
31-
public interface WebSocketInterceptor extends WebInterceptor {
32+
public interface WebSocketGraphQlHandlerInterceptor extends WebGraphQlHandlerInterceptor {
3233

3334
@Override
3435
default Mono<WebGraphQlResponse> intercept(WebGraphQlRequest request, Chain chain) {

spring-graphql/src/main/java/org/springframework/graphql/web/package-info.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
* WebSocket. Handlers are provided for use in ether
2020
* {@link org.springframework.graphql.web.webmvc Spring WebMvc} or
2121
* {@link org.springframework.graphql.web.webflux Spring WebFlux} with a common
22-
* {@link org.springframework.graphql.web.WebInterceptor interception} model that allows
23-
* applications to customize the request and response.
22+
* {@link org.springframework.graphql.web.WebGraphQlHandlerInterceptor interception}
23+
* model that allows applications to customize the request and response.
2424
*/
2525
@NonNullApi
2626
@NonNullFields

spring-graphql/src/main/java/org/springframework/graphql/web/webflux/GraphQlWebSocketHandler.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
import org.springframework.graphql.web.WebGraphQlRequest;
3636
import org.springframework.graphql.web.WebGraphQlHandler;
3737
import org.springframework.graphql.web.WebGraphQlResponse;
38-
import org.springframework.graphql.web.WebSocketInterceptor;
38+
import org.springframework.graphql.web.WebSocketGraphQlHandlerInterceptor;
3939
import org.springframework.graphql.web.support.GraphQlMessage;
4040
import org.springframework.http.codec.CodecConfigurer;
4141
import org.springframework.util.Assert;
@@ -63,7 +63,7 @@ public class GraphQlWebSocketHandler implements WebSocketHandler {
6363

6464
private final WebGraphQlHandler graphQlHandler;
6565

66-
private final WebSocketInterceptor webSocketInterceptor;
66+
private final WebSocketGraphQlHandlerInterceptor webSocketInterceptor;
6767

6868
private final CodecDelegate codecDelegate;
6969

0 commit comments

Comments
 (0)