From dfff40085cb3eaaa148c4698aaa19149b97ef2d4 Mon Sep 17 00:00:00 2001 From: rstoyanchev Date: Mon, 21 Mar 2022 09:02:11 +0000 Subject: [PATCH] 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. --- .../src/docs/asciidoc/index.adoc | 27 ++++++++++--------- .../src/docs/asciidoc/testing.adoc | 3 ++- .../graphql/test/tester/WebGraphQlTester.java | 3 ++- .../tester/WebGraphQlTesterBuilderTests.java | 6 ++--- .../web/DefaultWebGraphQlHandlerBuilder.java | 24 ++++++++--------- .../graphql/web/WebGraphQlHandler.java | 26 ++++++++++-------- ...java => WebGraphQlHandlerInterceptor.java} | 14 +++++----- ...> WebSocketGraphQlHandlerInterceptor.java} | 9 ++++--- .../graphql/web/package-info.java | 4 +-- .../web/webflux/GraphQlWebSocketHandler.java | 4 +-- .../web/webmvc/GraphQlWebSocketHandler.java | 4 +-- .../client/WebGraphQlClientBuilderTests.java | 6 ++--- ...ConsumeOneAndNeverCompleteInterceptor.java | 2 +- ...=> WebGraphQlHandlerInterceptorTests.java} | 6 ++--- .../graphql/web/WebGraphQlHandlerTests.java | 4 +-- .../web/WebSocketHandlerTestSupport.java | 4 +-- .../webflux/GraphQlWebSocketHandlerTests.java | 14 +++++----- .../webmvc/GraphQlWebSocketHandlerTests.java | 14 +++++----- .../springframework/graphql/GraphQlSetup.java | 10 +++---- .../graphql/web/WebGraphQlSetup.java | 2 +- 20 files changed, 97 insertions(+), 89 deletions(-) rename spring-graphql/src/main/java/org/springframework/graphql/web/{WebInterceptor.java => WebGraphQlHandlerInterceptor.java} (84%) rename spring-graphql/src/main/java/org/springframework/graphql/web/{WebSocketInterceptor.java => WebSocketGraphQlHandlerInterceptor.java} (88%) rename spring-graphql/src/test/java/org/springframework/graphql/web/{WebInterceptorTests.java => WebGraphQlHandlerInterceptorTests.java} (95%) diff --git a/spring-graphql-docs/src/docs/asciidoc/index.adoc b/spring-graphql-docs/src/docs/asciidoc/index.adoc index fb2be3a7..b9bede58 100644 --- a/spring-graphql-docs/src/docs/asciidoc/index.adoc +++ b/spring-graphql-docs/src/docs/asciidoc/index.adoc @@ -118,19 +118,19 @@ The Spring for GraphQL repository contains a WebFlux <> and <> transport handlers delegate to a common Web interception chain for request execution. The chain consists of a sequence of -`WebInterceptor` components, followed by a `ExecutionGraphQlService` that invokes -GraphQL Java. +`WebGraphQlHandlerInterceptor` components, followed by a `ExecutionGraphQlService` that +invokes GraphQL Java. -`WebInterceptor` is as a common contract to use in both Spring MVC and WebFlux -applications. Use it to intercept requests, inspect HTTP request headers, or to register a -transformation of the `graphql.ExecutionInput`: +`WebGraphQlHandlerInterceptor` is as a common contract to use in both Spring MVC and +WebFlux applications. Use it to intercept requests, inspect HTTP request headers, or to +register a transformation of the `graphql.ExecutionInput`: [source,java,indent=0,subs="verbatim,quotes"] ---- -class MyInterceptor implements WebInterceptor { +class MyInterceptor implements WebGraphQlHandlerInterceptor { @Override - public Mono intercept(WebGraphQlRequest request, WebInterceptorChain chain) { + public Mono intercept(WebGraphQlRequest request, Chain chain) { request.configureExecutionInput((executionInput, builder) -> { Map map = ... ; return builder.extensions(map).build(); @@ -140,15 +140,15 @@ class MyInterceptor implements WebInterceptor { } ---- -Use `WebInterceptor` also to intercept responses, add HTTP response headers, or transform -the `graphql.ExecutionResult`: +Use `WebGraphQlHandlerInterceptor` also to intercept responses, add HTTP response headers, +or transform the `graphql.ExecutionResult`: [source,java,indent=0,subs="verbatim,quotes"] ---- -class MyInterceptor implements WebInterceptor { +class MyInterceptor implements WebGraphQlHandlerInterceptor { @Override - public Mono intercept(WebGraphQlRequest request, WebInterceptorChain chain) { + public Mono intercept(WebGraphQlRequest request, Chain chain) { return chain.next(request) .map(response -> { Object data = response.getData(); @@ -423,7 +423,8 @@ thread and Reactor `Context` from the WebFlux processing pipeline. A `DataFetcher` and other components invoked by GraphQL Java may not always execute on the same thread as the Spring MVC handler, for example if an asynchronous -<> or `DataFetcher` switches to a different thread. +<> or `DataFetcher` switches to a +different thread. Spring for GraphQL supports propagating `ThreadLocal` values from the Servlet container thread to the thread a `DataFetcher` and other components invoked by GraphQL Java to @@ -467,7 +468,7 @@ Spring MVC application, see the A <> can rely on access to Reactor context that originates from the WebFlux request handling chain. This includes Reactor context -added by <> components. +added by <> components. diff --git a/spring-graphql-docs/src/docs/asciidoc/testing.adoc b/spring-graphql-docs/src/docs/asciidoc/testing.adoc index 39e987c9..041fa08d 100644 --- a/spring-graphql-docs/src/docs/asciidoc/testing.adoc +++ b/spring-graphql-docs/src/docs/asciidoc/testing.adoc @@ -197,7 +197,8 @@ a client. However, in some cases it's useful to involve server side transport handling with given mock transport input. The `WebGraphQlHandlerTester` extension lets you processes request through the -`WebInterceptor` chain before handing off to `ExecutionGraphQlService` for request execution: +`WebGraphQlHandlerInterceptor` chain before handing off to `ExecutionGraphQlService` for +request execution: [source,java,indent=0,subs="verbatim,quotes"] ---- diff --git a/spring-graphql-test/src/main/java/org/springframework/graphql/test/tester/WebGraphQlTester.java b/spring-graphql-test/src/main/java/org/springframework/graphql/test/tester/WebGraphQlTester.java index 4bf91432..df603c5f 100644 --- a/spring-graphql-test/src/main/java/org/springframework/graphql/test/tester/WebGraphQlTester.java +++ b/spring-graphql-test/src/main/java/org/springframework/graphql/test/tester/WebGraphQlTester.java @@ -26,7 +26,8 @@ import org.springframework.http.codec.CodecConfigurer; /** * Server-side tester, without a client, that executes requests through a * {@link WebGraphQlHandler}. Similar to {@link GraphQlServiceTester} but also - * adding a web processing layer with a {@code WebInterceptor} chain. + * adding a web processing layer with a {@code WebGraphQlHandlerInterceptor} + * chain. * * @author Rossen Stoyanchev * @since 1.0.0 diff --git a/spring-graphql-test/src/test/java/org/springframework/graphql/test/tester/WebGraphQlTesterBuilderTests.java b/spring-graphql-test/src/test/java/org/springframework/graphql/test/tester/WebGraphQlTesterBuilderTests.java index b2402555..cbdd1ed1 100644 --- a/spring-graphql-test/src/test/java/org/springframework/graphql/test/tester/WebGraphQlTesterBuilderTests.java +++ b/spring-graphql-test/src/test/java/org/springframework/graphql/test/tester/WebGraphQlTesterBuilderTests.java @@ -41,7 +41,7 @@ import org.springframework.graphql.web.WebGraphQlRequest; import org.springframework.graphql.web.TestWebSocketClient; import org.springframework.graphql.web.TestWebSocketConnection; import org.springframework.graphql.web.WebGraphQlHandler; -import org.springframework.graphql.web.WebInterceptor; +import org.springframework.graphql.web.WebGraphQlHandlerInterceptor; import org.springframework.graphql.web.webflux.GraphQlHttpHandler; import org.springframework.graphql.web.webflux.GraphQlWebSocketHandler; import org.springframework.http.codec.ClientCodecConfigurer; @@ -60,8 +60,8 @@ import static org.springframework.web.reactive.function.server.RouterFunctions.r /** * Tests for the builders of Web {@code GraphQlTester} extensions, using a - * {@link WebInterceptor} to capture the WebGraphQlRequest on the server side, - * and optionally returning a mock response, or an empty response. + * {@link WebGraphQlHandlerInterceptor} to capture the WebGraphQlRequest on the + * server side, and optionally returning a mock response, or an empty response. * *
    *
  • {@link HttpGraphQlTester} via {@link WebTestClient} to {@link GraphQlHttpHandler} diff --git a/spring-graphql/src/main/java/org/springframework/graphql/web/DefaultWebGraphQlHandlerBuilder.java b/spring-graphql/src/main/java/org/springframework/graphql/web/DefaultWebGraphQlHandlerBuilder.java index 5b0f4be0..c259c6cc 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/web/DefaultWebGraphQlHandlerBuilder.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/web/DefaultWebGraphQlHandlerBuilder.java @@ -39,10 +39,10 @@ class DefaultWebGraphQlHandlerBuilder implements WebGraphQlHandler.Builder { private final ExecutionGraphQlService service; - private final List interceptors = new ArrayList<>(); + private final List interceptors = new ArrayList<>(); @Nullable - private WebSocketInterceptor webSocketInterceptor; + private WebSocketGraphQlHandlerInterceptor webSocketInterceptor; @Nullable private List accessors; @@ -55,17 +55,17 @@ class DefaultWebGraphQlHandlerBuilder implements WebGraphQlHandler.Builder { @Override - public WebGraphQlHandler.Builder interceptor(WebInterceptor... interceptors) { + public WebGraphQlHandler.Builder interceptor(WebGraphQlHandlerInterceptor... interceptors) { return interceptors(Arrays.asList(interceptors)); } @Override - public WebGraphQlHandler.Builder interceptors(List interceptors) { + public WebGraphQlHandler.Builder interceptors(List interceptors) { this.interceptors.addAll(interceptors); interceptors.forEach(interceptor -> { - if (interceptor instanceof WebSocketInterceptor) { + if (interceptor instanceof WebSocketGraphQlHandlerInterceptor) { Assert.isNull(this.webSocketInterceptor, "There can be at most 1 WebSocketInterceptor"); - this.webSocketInterceptor = (WebSocketInterceptor) interceptor; + this.webSocketInterceptor = (WebSocketGraphQlHandlerInterceptor) interceptor; } }); return this; @@ -88,12 +88,12 @@ class DefaultWebGraphQlHandlerBuilder implements WebGraphQlHandler.Builder { @Override public WebGraphQlHandler build() { - WebInterceptor.Chain endOfChain = + WebGraphQlHandlerInterceptor.Chain endOfChain = request -> this.service.execute(request).map(WebGraphQlResponse::new); - WebInterceptor.Chain chain = this.interceptors.stream() - .reduce(WebInterceptor::andThen) - .map(interceptor -> (WebInterceptor.Chain) (request) -> interceptor.intercept(request, endOfChain)) + WebGraphQlHandlerInterceptor.Chain chain = this.interceptors.stream() + .reduce(WebGraphQlHandlerInterceptor::andThen) + .map(interceptor -> (WebGraphQlHandlerInterceptor.Chain) (request) -> interceptor.intercept(request, endOfChain)) .orElse(endOfChain); return new WebGraphQlHandler() { @@ -111,8 +111,8 @@ class DefaultWebGraphQlHandlerBuilder implements WebGraphQlHandler.Builder { } @Override - public WebSocketInterceptor webSocketInterceptor() { - return (webSocketInterceptor != null ? webSocketInterceptor : new WebSocketInterceptor() {}); + public WebSocketGraphQlHandlerInterceptor webSocketInterceptor() { + return (webSocketInterceptor != null ? webSocketInterceptor : new WebSocketGraphQlHandlerInterceptor() {}); } }; diff --git a/spring-graphql/src/main/java/org/springframework/graphql/web/WebGraphQlHandler.java b/spring-graphql/src/main/java/org/springframework/graphql/web/WebGraphQlHandler.java index 46d9e9e8..e95421d3 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/web/WebGraphQlHandler.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/web/WebGraphQlHandler.java @@ -42,10 +42,11 @@ public interface WebGraphQlHandler { Mono handleRequest(WebGraphQlRequest request); /** - * Return the single interceptor of type {@link WebSocketInterceptor} among - * all the configured interceptors. + * Return the single interceptor of type + * {@link WebSocketGraphQlHandlerInterceptor} among all the configured + * interceptors. */ - WebSocketInterceptor webSocketInterceptor(); + WebSocketGraphQlHandlerInterceptor webSocketInterceptor(); /** @@ -61,28 +62,31 @@ public interface WebGraphQlHandler { /** * Builder for a {@link WebGraphQlHandler} that executes a - * {@link WebInterceptor} chain followed by a {@link ExecutionGraphQlService}. + * {@link WebGraphQlHandlerInterceptor} chain followed by a + * {@link ExecutionGraphQlService}. */ interface Builder { /** * Configure interceptors to be invoked before the target * {@code GraphQlService}. - *

    One of the interceptors can be of type {@link WebSocketInterceptor} - * to handle data from the first {@code ConnectionInit} message expected - * on a GraphQL over WebSocket session, as well as the {@code Complete} - * message expected at the end of a session. + *

    One of the interceptors can be of type + * {@link WebSocketGraphQlHandlerInterceptor} to handle data from the + * first {@code ConnectionInit} message expected on a GraphQL over + * WebSocket session, as well as the {@code Complete} message expected + * at the end of a session. * @param interceptors the interceptors to add * @return this builder */ - Builder interceptor(WebInterceptor... interceptors); + Builder interceptor(WebGraphQlHandlerInterceptor... interceptors); /** - * Alternative to {@link #interceptor(WebInterceptor...)} with a List. + * Alternative to {@link #interceptor(WebGraphQlHandlerInterceptor...)} + * with a List. * @param interceptors the list of interceptors to add * @return this builder */ - Builder interceptors(List interceptors); + Builder interceptors(List interceptors); /** * Configure accessors for ThreadLocal variables to use to extract diff --git a/spring-graphql/src/main/java/org/springframework/graphql/web/WebInterceptor.java b/spring-graphql/src/main/java/org/springframework/graphql/web/WebGraphQlHandlerInterceptor.java similarity index 84% rename from spring-graphql/src/main/java/org/springframework/graphql/web/WebInterceptor.java rename to spring-graphql/src/main/java/org/springframework/graphql/web/WebGraphQlHandlerInterceptor.java index 053f002c..15364542 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/web/WebInterceptor.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/web/WebGraphQlHandlerInterceptor.java @@ -37,9 +37,9 @@ import org.springframework.util.Assert; * * @author Rossen Stoyanchev * @since 1.0.0 - * @see WebSocketInterceptor + * @see WebSocketGraphQlHandlerInterceptor */ -public interface WebInterceptor { +public interface WebGraphQlHandlerInterceptor { /** * Intercept a request and delegate to the rest of the chain including other @@ -51,13 +51,13 @@ public interface WebInterceptor { Mono intercept(WebGraphQlRequest request, Chain chain); /** - * Return a new {@link WebInterceptor} that invokes the current interceptor - * first and then the one that is passed in. + * Return a new {@link WebGraphQlHandlerInterceptor} that invokes the current + * interceptor first and then the one that is passed in. * @param interceptor the interceptor to delegate to after "this" - * @return the new {@code WebInterceptor} + * @return the new {@code WebGraphQlHandlerInterceptor} */ - default WebInterceptor andThen(WebInterceptor interceptor) { - Assert.notNull(interceptor, "WebInterceptor is required"); + default WebGraphQlHandlerInterceptor andThen(WebGraphQlHandlerInterceptor interceptor) { + Assert.notNull(interceptor, "WebGraphQlHandlerInterceptor is required"); return (request, chain) -> { Chain nextChain = nextRequest -> interceptor.intercept(nextRequest, chain); return intercept(request, nextChain); diff --git a/spring-graphql/src/main/java/org/springframework/graphql/web/WebSocketInterceptor.java b/spring-graphql/src/main/java/org/springframework/graphql/web/WebSocketGraphQlHandlerInterceptor.java similarity index 88% rename from spring-graphql/src/main/java/org/springframework/graphql/web/WebSocketInterceptor.java rename to spring-graphql/src/main/java/org/springframework/graphql/web/WebSocketGraphQlHandlerInterceptor.java index e3a79d6b..41114ef3 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/web/WebSocketInterceptor.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/web/WebSocketGraphQlHandlerInterceptor.java @@ -21,14 +21,15 @@ import reactor.core.publisher.Mono; /** - * An extension of {@link WebInterceptor} with additional methods to handle the - * start and end of a WebSocket connection. Only a single interceptor of type - * {@link WebSocketInterceptor} may be declared. + * An extension of {@link WebGraphQlHandlerInterceptor} with additional methods + * to handle the start and end of a WebSocket connection. Only a single + * interceptor of type {@link WebSocketGraphQlHandlerInterceptor} may be + * declared. * * @author Rossen Stoyanchev * @since 1.0.0 */ -public interface WebSocketInterceptor extends WebInterceptor { +public interface WebSocketGraphQlHandlerInterceptor extends WebGraphQlHandlerInterceptor { @Override default Mono intercept(WebGraphQlRequest request, Chain chain) { diff --git a/spring-graphql/src/main/java/org/springframework/graphql/web/package-info.java b/spring-graphql/src/main/java/org/springframework/graphql/web/package-info.java index 98dc93fa..c3a4be29 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/web/package-info.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/web/package-info.java @@ -19,8 +19,8 @@ * WebSocket. Handlers are provided for use in ether * {@link org.springframework.graphql.web.webmvc Spring WebMvc} or * {@link org.springframework.graphql.web.webflux Spring WebFlux} with a common - * {@link org.springframework.graphql.web.WebInterceptor interception} model that allows - * applications to customize the request and response. + * {@link org.springframework.graphql.web.WebGraphQlHandlerInterceptor interception} + * model that allows applications to customize the request and response. */ @NonNullApi @NonNullFields diff --git a/spring-graphql/src/main/java/org/springframework/graphql/web/webflux/GraphQlWebSocketHandler.java b/spring-graphql/src/main/java/org/springframework/graphql/web/webflux/GraphQlWebSocketHandler.java index 2cae7a63..5ecc9751 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/web/webflux/GraphQlWebSocketHandler.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/web/webflux/GraphQlWebSocketHandler.java @@ -35,7 +35,7 @@ import reactor.core.publisher.Mono; import org.springframework.graphql.web.WebGraphQlRequest; import org.springframework.graphql.web.WebGraphQlHandler; import org.springframework.graphql.web.WebGraphQlResponse; -import org.springframework.graphql.web.WebSocketInterceptor; +import org.springframework.graphql.web.WebSocketGraphQlHandlerInterceptor; import org.springframework.graphql.web.support.GraphQlMessage; import org.springframework.http.codec.CodecConfigurer; import org.springframework.util.Assert; @@ -63,7 +63,7 @@ public class GraphQlWebSocketHandler implements WebSocketHandler { private final WebGraphQlHandler graphQlHandler; - private final WebSocketInterceptor webSocketInterceptor; + private final WebSocketGraphQlHandlerInterceptor webSocketInterceptor; private final CodecDelegate codecDelegate; diff --git a/spring-graphql/src/main/java/org/springframework/graphql/web/webmvc/GraphQlWebSocketHandler.java b/spring-graphql/src/main/java/org/springframework/graphql/web/webmvc/GraphQlWebSocketHandler.java index d1d66cf6..1421ad82 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/web/webmvc/GraphQlWebSocketHandler.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/web/webmvc/GraphQlWebSocketHandler.java @@ -46,7 +46,7 @@ import reactor.core.scheduler.Schedulers; import org.springframework.graphql.web.WebGraphQlHandler; import org.springframework.graphql.web.WebGraphQlRequest; import org.springframework.graphql.web.WebGraphQlResponse; -import org.springframework.graphql.web.WebSocketInterceptor; +import org.springframework.graphql.web.WebSocketGraphQlHandlerInterceptor; import org.springframework.graphql.web.support.GraphQlMessage; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpInputMessage; @@ -81,7 +81,7 @@ public class GraphQlWebSocketHandler extends TextWebSocketHandler implements Sub private final WebGraphQlHandler graphQlHandler; - private final WebSocketInterceptor webSocketInterceptor; + private final WebSocketGraphQlHandlerInterceptor webSocketInterceptor; private final Duration initTimeoutDuration; diff --git a/spring-graphql/src/test/java/org/springframework/graphql/client/WebGraphQlClientBuilderTests.java b/spring-graphql/src/test/java/org/springframework/graphql/client/WebGraphQlClientBuilderTests.java index df7e8c47..c5ca7b6a 100644 --- a/spring-graphql/src/test/java/org/springframework/graphql/client/WebGraphQlClientBuilderTests.java +++ b/spring-graphql/src/test/java/org/springframework/graphql/client/WebGraphQlClientBuilderTests.java @@ -41,7 +41,7 @@ import org.springframework.graphql.web.WebGraphQlRequest; import org.springframework.graphql.web.TestWebSocketClient; import org.springframework.graphql.web.TestWebSocketConnection; import org.springframework.graphql.web.WebGraphQlHandler; -import org.springframework.graphql.web.WebInterceptor; +import org.springframework.graphql.web.WebGraphQlHandlerInterceptor; import org.springframework.graphql.web.webflux.GraphQlHttpHandler; import org.springframework.graphql.web.webflux.GraphQlWebSocketHandler; import org.springframework.http.codec.ClientCodecConfigurer; @@ -63,8 +63,8 @@ import static org.springframework.web.reactive.function.server.RouterFunctions.r /** * Tests for the builders of Web {@code GraphQlClient} extensions, using a - * {@link WebInterceptor} to capture the WebInput on the server side, and - * optionally returning a mock response, or an empty response. + * {@link WebGraphQlHandlerInterceptor} to capture the WebInput on the server + * side, and optionally returning a mock response, or an empty response. * *

      *
    • {@link HttpGraphQlClient} via {@link HttpHandlerConnector} to {@link GraphQlHttpHandler} diff --git a/spring-graphql/src/test/java/org/springframework/graphql/web/ConsumeOneAndNeverCompleteInterceptor.java b/spring-graphql/src/test/java/org/springframework/graphql/web/ConsumeOneAndNeverCompleteInterceptor.java index 8d25dc76..841ff9f2 100644 --- a/spring-graphql/src/test/java/org/springframework/graphql/web/ConsumeOneAndNeverCompleteInterceptor.java +++ b/spring-graphql/src/test/java/org/springframework/graphql/web/ConsumeOneAndNeverCompleteInterceptor.java @@ -20,7 +20,7 @@ import org.reactivestreams.Publisher; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; -public class ConsumeOneAndNeverCompleteInterceptor implements WebInterceptor { +public class ConsumeOneAndNeverCompleteInterceptor implements WebGraphQlHandlerInterceptor { @Override public Mono intercept(WebGraphQlRequest request, Chain chain) { diff --git a/spring-graphql/src/test/java/org/springframework/graphql/web/WebInterceptorTests.java b/spring-graphql/src/test/java/org/springframework/graphql/web/WebGraphQlHandlerInterceptorTests.java similarity index 95% rename from spring-graphql/src/test/java/org/springframework/graphql/web/WebInterceptorTests.java rename to spring-graphql/src/test/java/org/springframework/graphql/web/WebGraphQlHandlerInterceptorTests.java index 9c73d5c7..bef35652 100644 --- a/spring-graphql/src/test/java/org/springframework/graphql/web/WebInterceptorTests.java +++ b/spring-graphql/src/test/java/org/springframework/graphql/web/WebGraphQlHandlerInterceptorTests.java @@ -35,9 +35,9 @@ import org.springframework.http.HttpHeaders; import static org.assertj.core.api.Assertions.assertThat; /** - * Unit tests for a {@link WebInterceptor} chain. + * Unit tests for a {@link WebGraphQlHandlerInterceptor} chain. */ -public class WebInterceptorTests { +public class WebGraphQlHandlerInterceptorTests { private static final WebGraphQlRequest webRequest = new WebGraphQlRequest( URI.create("http://abc.org"), new HttpHeaders(), Collections.singletonMap("query", "{ notUsed }"), "1", null); @@ -98,7 +98,7 @@ public class WebInterceptorTests { ExecutionResultImpl.newExecutionResult().build())); } - private static class OrderInterceptor implements WebInterceptor { + private static class OrderInterceptor implements WebGraphQlHandlerInterceptor { private final StringBuilder sb; diff --git a/spring-graphql/src/test/java/org/springframework/graphql/web/WebGraphQlHandlerTests.java b/spring-graphql/src/test/java/org/springframework/graphql/web/WebGraphQlHandlerTests.java index 689778e2..1c2aa466 100644 --- a/spring-graphql/src/test/java/org/springframework/graphql/web/WebGraphQlHandlerTests.java +++ b/spring-graphql/src/test/java/org/springframework/graphql/web/WebGraphQlHandlerTests.java @@ -99,7 +99,7 @@ public class WebGraphQlHandlerTests { Mono responseMono = this.graphQlSetup .queryFetcher("greeting", env -> "Hello " + nameThreadLocal.get()) - .webInterceptor((input, next) -> Mono.delay(Duration.ofMillis(10)).flatMap((aLong) -> next.next(input))) + .interceptor((input, next) -> Mono.delay(Duration.ofMillis(10)).flatMap((aLong) -> next.next(input))) .threadLocalAccessor(threadLocalAccessor) .toWebGraphQlHandler() .handleRequest(webInput); @@ -126,7 +126,7 @@ public class WebGraphQlHandlerTests { Mono responseMono = this.graphQlSetup.queryFetcher("greeting", this.errorDataFetcher) .exceptionResolver(exceptionResolver) - .webInterceptor((input, next) -> Mono.delay(Duration.ofMillis(10)).flatMap((aLong) -> next.next(input))) + .interceptor((input, next) -> Mono.delay(Duration.ofMillis(10)).flatMap((aLong) -> next.next(input))) .threadLocalAccessor(threadLocalAccessor) .toWebGraphQlHandler() .handleRequest(webInput); diff --git a/spring-graphql/src/test/java/org/springframework/graphql/web/WebSocketHandlerTestSupport.java b/spring-graphql/src/test/java/org/springframework/graphql/web/WebSocketHandlerTestSupport.java index de43c090..6f9d6e2f 100644 --- a/spring-graphql/src/test/java/org/springframework/graphql/web/WebSocketHandlerTestSupport.java +++ b/spring-graphql/src/test/java/org/springframework/graphql/web/WebSocketHandlerTestSupport.java @@ -64,7 +64,7 @@ public abstract class WebSocketHandlerTestSupport { "}"; - protected WebGraphQlHandler initHandler(WebInterceptor... interceptors) { + protected WebGraphQlHandler initHandler(WebGraphQlHandlerInterceptor... interceptors) { return GraphQlSetup.schemaResource(BookSource.schema) .queryFetcher("bookById", environment -> { Long id = Long.parseLong(environment.getArgument("id")); @@ -75,7 +75,7 @@ public abstract class WebSocketHandlerTestSupport { return Flux.fromIterable(BookSource.books()) .filter((book) -> book.getAuthor().getFullName().contains(author)); }) - .webInterceptor(interceptors) + .interceptor(interceptors) .toWebGraphQlHandler(); } diff --git a/spring-graphql/src/test/java/org/springframework/graphql/web/webflux/GraphQlWebSocketHandlerTests.java b/spring-graphql/src/test/java/org/springframework/graphql/web/webflux/GraphQlWebSocketHandlerTests.java index d2da508b..80e4a2c1 100644 --- a/spring-graphql/src/test/java/org/springframework/graphql/web/webflux/GraphQlWebSocketHandlerTests.java +++ b/spring-graphql/src/test/java/org/springframework/graphql/web/webflux/GraphQlWebSocketHandlerTests.java @@ -39,9 +39,9 @@ import org.springframework.core.io.buffer.DefaultDataBufferFactory; import org.springframework.graphql.GraphQlSetup; import org.springframework.graphql.web.ConsumeOneAndNeverCompleteInterceptor; import org.springframework.graphql.web.WebGraphQlHandler; -import org.springframework.graphql.web.WebInterceptor; +import org.springframework.graphql.web.WebGraphQlHandlerInterceptor; import org.springframework.graphql.web.WebSocketHandlerTestSupport; -import org.springframework.graphql.web.WebSocketInterceptor; +import org.springframework.graphql.web.WebSocketGraphQlHandlerInterceptor; import org.springframework.graphql.web.support.GraphQlMessage; import org.springframework.graphql.web.support.GraphQlMessageType; import org.springframework.http.codec.ServerCodecConfigurer; @@ -149,7 +149,7 @@ public class GraphQlWebSocketHandlerTests extends WebSocketHandlerTestSupport { void connectionInitHandling() { TestWebSocketSession session = handle( Flux.just(toWebSocketMessage("{\"type\":\"connection_init\",\"payload\":{\"key\":\"A\"}}")), - new WebSocketInterceptor() { + new WebSocketGraphQlHandlerInterceptor() { @Override public Mono handleConnectionInitialization(String sessionId, Map payload) { @@ -189,7 +189,7 @@ public class GraphQlWebSocketHandlerTests extends WebSocketHandlerTestSupport { TestWebSocketSession session = handle( Flux.just(toWebSocketMessage("{\"type\":\"connection_init\",\"payload\":{\"key\":\"A\"}}")), - new WebSocketInterceptor() { + new WebSocketGraphQlHandlerInterceptor() { @Override public void handleConnectionClosed(String sessionId, int status, Map payload) { @@ -209,7 +209,7 @@ public class GraphQlWebSocketHandlerTests extends WebSocketHandlerTestSupport { void connectionInitRejected() { TestWebSocketSession session = handle( Flux.just(toWebSocketMessage("{\"type\":\"connection_init\"}")), - new WebSocketInterceptor() { + new WebSocketGraphQlHandlerInterceptor() { @Override public Mono handleConnectionInitialization(String sessionId, Map payload) { @@ -322,7 +322,7 @@ public class GraphQlWebSocketHandlerTests extends WebSocketHandlerTestSupport { WebGraphQlHandler initHandler = GraphQlSetup.schemaContent(schema) .subscriptionFetcher("greeting", env -> Flux.just("a", null, "b")) - .webInterceptor() + .interceptor() .toWebGraphQlHandler(); GraphQlWebSocketHandler handler = new GraphQlWebSocketHandler( @@ -363,7 +363,7 @@ public class GraphQlWebSocketHandlerTests extends WebSocketHandlerTestSupport { .verify(TIMEOUT); } - private TestWebSocketSession handle(Flux input, WebInterceptor... interceptors) { + private TestWebSocketSession handle(Flux input, WebGraphQlHandlerInterceptor... interceptors) { GraphQlWebSocketHandler handler = new GraphQlWebSocketHandler( initHandler(interceptors), ServerCodecConfigurer.create(), diff --git a/spring-graphql/src/test/java/org/springframework/graphql/web/webmvc/GraphQlWebSocketHandlerTests.java b/spring-graphql/src/test/java/org/springframework/graphql/web/webmvc/GraphQlWebSocketHandlerTests.java index f5d714d7..3627f17b 100644 --- a/spring-graphql/src/test/java/org/springframework/graphql/web/webmvc/GraphQlWebSocketHandlerTests.java +++ b/spring-graphql/src/test/java/org/springframework/graphql/web/webmvc/GraphQlWebSocketHandlerTests.java @@ -37,9 +37,9 @@ import reactor.test.StepVerifier; import org.springframework.graphql.GraphQlSetup; import org.springframework.graphql.web.ConsumeOneAndNeverCompleteInterceptor; import org.springframework.graphql.web.WebGraphQlHandler; -import org.springframework.graphql.web.WebInterceptor; +import org.springframework.graphql.web.WebGraphQlHandlerInterceptor; import org.springframework.graphql.web.WebSocketHandlerTestSupport; -import org.springframework.graphql.web.WebSocketInterceptor; +import org.springframework.graphql.web.WebSocketGraphQlHandlerInterceptor; import org.springframework.graphql.web.support.GraphQlMessage; import org.springframework.graphql.web.support.GraphQlMessageType; import org.springframework.http.HttpHeaders; @@ -148,7 +148,7 @@ public class GraphQlWebSocketHandlerTests extends WebSocketHandlerTestSupport { @Test void connectionInitHandling() throws Exception { - WebSocketInterceptor interceptor = new WebSocketInterceptor() { + WebSocketGraphQlHandlerInterceptor interceptor = new WebSocketGraphQlHandlerInterceptor() { @Override public Mono handleConnectionInitialization(String sessionId, Map payload) { @@ -192,7 +192,7 @@ public class GraphQlWebSocketHandlerTests extends WebSocketHandlerTestSupport { CloseStatus closeStatus = CloseStatus.PROTOCOL_ERROR; AtomicBoolean called = new AtomicBoolean(); - WebSocketInterceptor interceptor = new WebSocketInterceptor() { + WebSocketGraphQlHandlerInterceptor interceptor = new WebSocketGraphQlHandlerInterceptor() { @Override public void handleConnectionClosed(String sessionId, int status, Map payload) { @@ -219,7 +219,7 @@ public class GraphQlWebSocketHandlerTests extends WebSocketHandlerTestSupport { @Test void connectionInitRejected() throws Exception { - WebSocketInterceptor interceptor = new WebSocketInterceptor() { + WebSocketGraphQlHandlerInterceptor interceptor = new WebSocketGraphQlHandlerInterceptor() { @Override public Mono handleConnectionInitialization(String sessionId, Map payload) { @@ -333,7 +333,7 @@ public class GraphQlWebSocketHandlerTests extends WebSocketHandlerTestSupport { WebGraphQlHandler initHandler = GraphQlSetup.schemaContent(schema) .subscriptionFetcher("greeting", env -> Flux.just("a", null, "b")) - .webInterceptor() + .interceptor() .toWebGraphQlHandler(); GraphQlWebSocketHandler handler = new GraphQlWebSocketHandler(initHandler, converter, Duration.ofSeconds(60)); @@ -378,7 +378,7 @@ public class GraphQlWebSocketHandlerTests extends WebSocketHandlerTestSupport { } } - private GraphQlWebSocketHandler initWebSocketHandler(WebInterceptor... interceptors) { + private GraphQlWebSocketHandler initWebSocketHandler(WebGraphQlHandlerInterceptor... interceptors) { try { return new GraphQlWebSocketHandler(initHandler(interceptors), converter, Duration.ofSeconds(60)); } diff --git a/spring-graphql/src/testFixtures/java/org/springframework/graphql/GraphQlSetup.java b/spring-graphql/src/testFixtures/java/org/springframework/graphql/GraphQlSetup.java index b3c08aa2..c17f8885 100644 --- a/spring-graphql/src/testFixtures/java/org/springframework/graphql/GraphQlSetup.java +++ b/spring-graphql/src/testFixtures/java/org/springframework/graphql/GraphQlSetup.java @@ -37,7 +37,7 @@ import org.springframework.graphql.execution.RuntimeWiringConfigurer; import org.springframework.graphql.execution.ThreadLocalAccessor; import org.springframework.graphql.web.WebGraphQlHandler; import org.springframework.graphql.web.WebGraphQlSetup; -import org.springframework.graphql.web.WebInterceptor; +import org.springframework.graphql.web.WebGraphQlHandlerInterceptor; /** * Workflow for GraphQL tests setup that starts with {@link GraphQlSource.Builder} @@ -53,7 +53,7 @@ public class GraphQlSetup implements GraphQlServiceSetup { private final List dataLoaderRegistrars = new ArrayList<>(); - private final List webInterceptors = new ArrayList<>(); + private final List interceptors = new ArrayList<>(); private final List accessors = new ArrayList<>(); @@ -134,8 +134,8 @@ public class GraphQlSetup implements GraphQlServiceSetup { // WebGraphQlSetup... - public WebGraphQlSetup webInterceptor(WebInterceptor... interceptors) { - this.webInterceptors.addAll(Arrays.asList(interceptors)); + public WebGraphQlSetup interceptor(WebGraphQlHandlerInterceptor... interceptors) { + this.interceptors.addAll(Arrays.asList(interceptors)); return this; } @@ -148,7 +148,7 @@ public class GraphQlSetup implements GraphQlServiceSetup { public WebGraphQlHandler toWebGraphQlHandler() { ExecutionGraphQlService service = toGraphQlService(); return WebGraphQlHandler.builder(service) - .interceptors(webInterceptors) + .interceptors(this.interceptors) .threadLocalAccessors(this.accessors) .build(); } diff --git a/spring-graphql/src/testFixtures/java/org/springframework/graphql/web/WebGraphQlSetup.java b/spring-graphql/src/testFixtures/java/org/springframework/graphql/web/WebGraphQlSetup.java index ee5ba0bb..036aaa10 100644 --- a/spring-graphql/src/testFixtures/java/org/springframework/graphql/web/WebGraphQlSetup.java +++ b/spring-graphql/src/testFixtures/java/org/springframework/graphql/web/WebGraphQlSetup.java @@ -25,7 +25,7 @@ import org.springframework.graphql.execution.ThreadLocalAccessor; */ public interface WebGraphQlSetup { - WebGraphQlSetup webInterceptor(WebInterceptor... interceptors); + WebGraphQlSetup interceptor(WebGraphQlHandlerInterceptor... interceptors); WebGraphQlSetup threadLocalAccessor(ThreadLocalAccessor... accessors);