Skip to content

Commit c0f97d3

Browse files
committed
Move WebInterceptorChain into WebInterceptor
Shorter name on method declaration within the interceptor, also for consistency with GraphQlClientInterceptor.
1 parent bb62808 commit c0f97d3

File tree

7 files changed

+32
-61
lines changed

7 files changed

+32
-61
lines changed

spring-graphql/src/main/java/org/springframework/graphql/client/GraphQlClientInterceptor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ interface Chain {
8484

8585
/**
8686
* Delegate to the rest of the chain to perform the request.
87-
* @param request the request to perform.
87+
* @param request the request to perform
8888
* @return {@code Mono} with the response
8989
* @see GraphQlClient.RequestSpec#execute()
9090
*/

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,12 @@ public WebGraphQlHandler.Builder threadLocalAccessors(List<ThreadLocalAccessor>
8888
@Override
8989
public WebGraphQlHandler build() {
9090

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

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

9999
return new WebGraphQlHandler() {

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

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@
2525
import org.springframework.util.Assert;
2626

2727
/**
28-
* Interceptor for the handling of GraphQL over HTTP or GraphQL over WebSocket
29-
* requests. Exposes the details of the underlying HTTP request or WebSocket
30-
* handshake, the decoded GraphQL request, and allows customization of the
31-
* {@link ExecutionInput} and the resulting {@link ExecutionResult}.
28+
* Interceptor for server handling of GraphQL over HTTP or WebSocket requests,
29+
* providing access info about the underlying HTTP request or WebSocket
30+
* handshake, and allowing customization of the {@link ExecutionInput} and
31+
* the {@link ExecutionResult}.
3232
*
3333
* <p>Interceptors are typically declared as beans in Spring configuration and
3434
* ordered as defined in {@link ObjectProvider#orderedStream()}.
@@ -42,16 +42,13 @@
4242
public interface WebInterceptor {
4343

4444
/**
45-
* Intercept a request and delegate to the rest of the chain that consists
46-
* of other interceptors followed by a
47-
* {@link ExecutionGraphQlService} that executes the
48-
* request through the GraphQL Java.
49-
* @param request provides access to GraphQL request and allows customization
50-
* of the {@link ExecutionInput} for {@link graphql.GraphQL}.
51-
* @param chain the rest of the chain to handle the request
45+
* Intercept a request and delegate to the rest of the chain including other
46+
* interceptors and a {@link ExecutionGraphQlService}.
47+
* @param request the request to execute
48+
* @param chain the rest of the chain to execute the request
5249
* @return a {@link Mono} with the response
5350
*/
54-
Mono<WebGraphQlResponse> intercept(WebGraphQlRequest request, WebInterceptorChain chain);
51+
Mono<WebGraphQlResponse> intercept(WebGraphQlRequest request, Chain chain);
5552

5653
/**
5754
* Return a new {@link WebInterceptor} that invokes the current interceptor
@@ -62,9 +59,24 @@ public interface WebInterceptor {
6259
default WebInterceptor andThen(WebInterceptor interceptor) {
6360
Assert.notNull(interceptor, "WebInterceptor is required");
6461
return (request, chain) -> {
65-
WebInterceptorChain nextChain = nextRequest -> interceptor.intercept(nextRequest, chain);
62+
Chain nextChain = nextRequest -> interceptor.intercept(nextRequest, chain);
6663
return intercept(request, nextChain);
6764
};
6865
}
6966

67+
68+
/**
69+
* Contract for delegation to the rest of the chain.
70+
*/
71+
interface Chain {
72+
73+
/**
74+
* Delegate to the rest of the chain to execute the request.
75+
* @param request the request to execute
76+
* the {@link ExecutionInput} for {@link graphql.GraphQL}.
77+
* @return {@code Mono} with the response
78+
*/
79+
Mono<WebGraphQlResponse> next(WebGraphQlRequest request);
80+
81+
}
7082
}

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

Lines changed: 0 additions & 41 deletions
This file was deleted.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
public interface WebSocketInterceptor extends WebInterceptor {
3232

3333
@Override
34-
default Mono<WebGraphQlResponse> intercept(WebGraphQlRequest request, WebInterceptorChain chain) {
34+
default Mono<WebGraphQlResponse> intercept(WebGraphQlRequest request, Chain chain) {
3535
return chain.next(request);
3636
}
3737

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
public class ConsumeOneAndNeverCompleteInterceptor implements WebInterceptor {
2424

2525
@Override
26-
public Mono<WebGraphQlResponse> intercept(WebGraphQlRequest request, WebInterceptorChain chain) {
26+
public Mono<WebGraphQlResponse> intercept(WebGraphQlRequest request, Chain chain) {
2727
return chain.next(request).map(response -> response.transform(builder -> {
2828
Object originalData = response.getData();
2929
if (originalData instanceof Publisher) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ private static class OrderInterceptor implements WebInterceptor {
110110
}
111111

112112
@Override
113-
public Mono<WebGraphQlResponse> intercept(WebGraphQlRequest request, WebInterceptorChain chain) {
113+
public Mono<WebGraphQlResponse> intercept(WebGraphQlRequest request, Chain chain) {
114114
this.sb.append(":pre").append(this.order);
115115
return chain.next(request)
116116
.map((response) -> {

0 commit comments

Comments
 (0)