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.
This commit is contained in:
@@ -118,19 +118,19 @@ The Spring for GraphQL repository contains a WebFlux
|
||||
|
||||
<<web-http>> and <<web-websocket>> 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<WebGraphQlResponse> intercept(WebGraphQlRequest request, WebInterceptorChain chain) {
|
||||
public Mono<WebGraphQlResponse> intercept(WebGraphQlRequest request, Chain chain) {
|
||||
request.configureExecutionInput((executionInput, builder) -> {
|
||||
Map<String, Object> 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<WebGraphQlResponse> intercept(WebGraphQlRequest request, WebInterceptorChain chain) {
|
||||
public Mono<WebGraphQlResponse> 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
|
||||
<<web-interception, `WebInterceptor`>> or `DataFetcher` switches to a different thread.
|
||||
<<web-interception, `WebGraphQlHandlerInterceptor`>> 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 <<execution-reactive-datafetcher>> can rely on access to Reactor context that
|
||||
originates from the WebFlux request handling chain. This includes Reactor context
|
||||
added by <<web-interception, WebInterceptor>> components.
|
||||
added by <<web-interception, WebGraphQlHandlerInterceptor>> components.
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -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"]
|
||||
----
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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.
|
||||
*
|
||||
* <ul>
|
||||
* <li>{@link HttpGraphQlTester} via {@link WebTestClient} to {@link GraphQlHttpHandler}
|
||||
|
||||
@@ -39,10 +39,10 @@ class DefaultWebGraphQlHandlerBuilder implements WebGraphQlHandler.Builder {
|
||||
|
||||
private final ExecutionGraphQlService service;
|
||||
|
||||
private final List<WebInterceptor> interceptors = new ArrayList<>();
|
||||
private final List<WebGraphQlHandlerInterceptor> interceptors = new ArrayList<>();
|
||||
|
||||
@Nullable
|
||||
private WebSocketInterceptor webSocketInterceptor;
|
||||
private WebSocketGraphQlHandlerInterceptor webSocketInterceptor;
|
||||
|
||||
@Nullable
|
||||
private List<ThreadLocalAccessor> 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<WebInterceptor> interceptors) {
|
||||
public WebGraphQlHandler.Builder interceptors(List<WebGraphQlHandlerInterceptor> 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() {});
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
@@ -42,10 +42,11 @@ public interface WebGraphQlHandler {
|
||||
Mono<WebGraphQlResponse> 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}.
|
||||
* <p>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.
|
||||
* <p>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<WebInterceptor> interceptors);
|
||||
Builder interceptors(List<WebGraphQlHandlerInterceptor> interceptors);
|
||||
|
||||
/**
|
||||
* Configure accessors for ThreadLocal variables to use to extract
|
||||
|
||||
@@ -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<WebGraphQlResponse> 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);
|
||||
@@ -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<WebGraphQlResponse> intercept(WebGraphQlRequest request, Chain chain) {
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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.
|
||||
*
|
||||
* <ul>
|
||||
* <li>{@link HttpGraphQlClient} via {@link HttpHandlerConnector} to {@link GraphQlHttpHandler}
|
||||
|
||||
@@ -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<WebGraphQlResponse> intercept(WebGraphQlRequest request, Chain chain) {
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -99,7 +99,7 @@ public class WebGraphQlHandlerTests {
|
||||
|
||||
Mono<WebGraphQlResponse> 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<WebGraphQlResponse> 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);
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
@@ -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<Object> handleConnectionInitialization(String sessionId, Map<String, Object> 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<String, Object> 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<Object> handleConnectionInitialization(String sessionId, Map<String, Object> 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<WebSocketMessage> input, WebInterceptor... interceptors) {
|
||||
private TestWebSocketSession handle(Flux<WebSocketMessage> input, WebGraphQlHandlerInterceptor... interceptors) {
|
||||
GraphQlWebSocketHandler handler = new GraphQlWebSocketHandler(
|
||||
initHandler(interceptors),
|
||||
ServerCodecConfigurer.create(),
|
||||
|
||||
@@ -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<Object> handleConnectionInitialization(String sessionId, Map<String, Object> 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<String, Object> 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<Object> handleConnectionInitialization(String sessionId, Map<String, Object> 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));
|
||||
}
|
||||
|
||||
@@ -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<DataLoaderRegistrar> dataLoaderRegistrars = new ArrayList<>();
|
||||
|
||||
private final List<WebInterceptor> webInterceptors = new ArrayList<>();
|
||||
private final List<WebGraphQlHandlerInterceptor> interceptors = new ArrayList<>();
|
||||
|
||||
private final List<ThreadLocalAccessor> 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();
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user