Skip to content

Commit

Permalink
Shorten names of [Web|RSocket]GraphQlHandlerInterceptor
Browse files Browse the repository at this point in the history
See gh-339
  • Loading branch information
rstoyanchev committed Mar 28, 2022
1 parent 36425af commit 6584b88
Show file tree
Hide file tree
Showing 21 changed files with 69 additions and 69 deletions.
14 changes: 7 additions & 7 deletions spring-graphql-docs/src/docs/asciidoc/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -118,16 +118,16 @@ 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
`WebGraphQlHandlerInterceptor` components, followed by a `ExecutionGraphQlService` that
`WebGraphQlInterceptor` components, followed by a `ExecutionGraphQlService` that
invokes GraphQL Java.

`WebGraphQlHandlerInterceptor` is as a common contract to use in both Spring MVC and
`WebGraphQlInterceptor` 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 WebGraphQlHandlerInterceptor {
class MyInterceptor implements WebGraphQlInterceptor {
@Override
public Mono<WebGraphQlResponse> intercept(WebGraphQlRequest request, Chain chain) {
Expand All @@ -140,12 +140,12 @@ class MyInterceptor implements WebGraphQlHandlerInterceptor {
}
----

Use `WebGraphQlHandlerInterceptor` also to intercept responses, add HTTP response headers,
Use `WebGraphQlInterceptor` also to intercept responses, add HTTP response headers,
or transform the `graphql.ExecutionResult`:

[source,java,indent=0,subs="verbatim,quotes"]
----
class MyInterceptor implements WebGraphQlHandlerInterceptor {
class MyInterceptor implements WebGraphQlInterceptor {
@Override
public Mono<WebGraphQlResponse> intercept(WebGraphQlRequest request, Chain chain) {
Expand Down Expand Up @@ -423,7 +423,7 @@ 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, `WebGraphQlHandlerInterceptor`>> or `DataFetcher` switches to a
<<web-interception, `WebGraphQlInterceptor`>> or `DataFetcher` switches to a
different thread.

Spring for GraphQL supports propagating `ThreadLocal` values from the Servlet container
Expand Down Expand Up @@ -468,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, WebGraphQlHandlerInterceptor>> components.
added by <<web-interception, WebGraphQlInterceptor>> components.



Expand Down
2 changes: 1 addition & 1 deletion spring-graphql-docs/src/docs/asciidoc/testing.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ 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
`WebGraphQlHandlerInterceptor` chain before handing off to `ExecutionGraphQlService` for
`WebGraphQlInterceptor` chain before handing off to `ExecutionGraphQlService` for
request execution:

[source,java,indent=0,subs="verbatim,quotes"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
/**
* 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 WebGraphQlHandlerInterceptor}
* adding a web processing layer with a {@code WebGraphQlInterceptor}
* chain.
*
* @author Rossen Stoyanchev
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
import org.springframework.graphql.web.TestWebSocketClient;
import org.springframework.graphql.web.TestWebSocketConnection;
import org.springframework.graphql.web.WebGraphQlHandler;
import org.springframework.graphql.web.WebGraphQlHandlerInterceptor;
import org.springframework.graphql.web.WebGraphQlInterceptor;
import org.springframework.graphql.web.webflux.GraphQlHttpHandler;
import org.springframework.graphql.web.webflux.GraphQlWebSocketHandler;
import org.springframework.http.codec.ClientCodecConfigurer;
Expand All @@ -60,7 +60,7 @@

/**
* Tests for the builders of Web {@code GraphQlTester} extensions, using a
* {@link WebGraphQlHandlerInterceptor} to capture the WebGraphQlRequest on the
* {@link WebGraphQlInterceptor} to capture the WebGraphQlRequest on the
* server side, and optionally returning a mock response, or an empty response.
*
* <ul>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import org.springframework.graphql.ExecutionGraphQlService;
import org.springframework.graphql.execution.ReactorContextManager;
import org.springframework.graphql.execution.ThreadLocalAccessor;
import org.springframework.graphql.web.WebGraphQlHandlerInterceptor.Chain;
import org.springframework.graphql.web.WebGraphQlInterceptor.Chain;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;
Expand All @@ -40,10 +40,10 @@ class DefaultWebGraphQlHandlerBuilder implements WebGraphQlHandler.Builder {

private final ExecutionGraphQlService service;

private final List<WebGraphQlHandlerInterceptor> interceptors = new ArrayList<>();
private final List<WebGraphQlInterceptor> interceptors = new ArrayList<>();

@Nullable
private WebSocketGraphQlHandlerInterceptor webSocketInterceptor;
private WebSocketGraphQlInterceptor webSocketInterceptor;

@Nullable
private List<ThreadLocalAccessor> accessors;
Expand All @@ -56,17 +56,17 @@ class DefaultWebGraphQlHandlerBuilder implements WebGraphQlHandler.Builder {


@Override
public WebGraphQlHandler.Builder interceptor(WebGraphQlHandlerInterceptor... interceptors) {
public WebGraphQlHandler.Builder interceptor(WebGraphQlInterceptor... interceptors) {
return interceptors(Arrays.asList(interceptors));
}

@Override
public WebGraphQlHandler.Builder interceptors(List<WebGraphQlHandlerInterceptor> interceptors) {
public WebGraphQlHandler.Builder interceptors(List<WebGraphQlInterceptor> interceptors) {
this.interceptors.addAll(interceptors);
interceptors.forEach(interceptor -> {
if (interceptor instanceof WebSocketGraphQlHandlerInterceptor) {
if (interceptor instanceof WebSocketGraphQlInterceptor) {
Assert.isNull(this.webSocketInterceptor, "There can be at most 1 WebSocketInterceptor");
this.webSocketInterceptor = (WebSocketGraphQlHandlerInterceptor) interceptor;
this.webSocketInterceptor = (WebSocketGraphQlInterceptor) interceptor;
}
});
return this;
Expand All @@ -92,7 +92,7 @@ public WebGraphQlHandler build() {
Chain endOfChain = request -> this.service.execute(request).map(WebGraphQlResponse::new);

Chain chain = this.interceptors.stream()
.reduce(WebGraphQlHandlerInterceptor::andThen)
.reduce(WebGraphQlInterceptor::andThen)
.map(interceptor -> (Chain) (request) -> interceptor.intercept(request, endOfChain))
.orElse(endOfChain);

Expand All @@ -111,9 +111,9 @@ public Mono<WebGraphQlResponse> handleRequest(WebGraphQlRequest request) {
}

@Override
public WebSocketGraphQlHandlerInterceptor webSocketInterceptor() {
public WebSocketGraphQlInterceptor webSocketInterceptor() {
return (webSocketInterceptor != null ?
webSocketInterceptor : new WebSocketGraphQlHandlerInterceptor() {});
webSocketInterceptor : new WebSocketGraphQlInterceptor() {});
}

};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

import org.springframework.graphql.ExecutionGraphQlResponse;
import org.springframework.graphql.ExecutionGraphQlService;
import org.springframework.graphql.web.RSocketGraphQlHandlerInterceptor.Chain;
import org.springframework.graphql.web.RSocketGraphQlInterceptor.Chain;
import org.springframework.util.AlternativeJdkIdGenerator;
import org.springframework.util.IdGenerator;

Expand Down Expand Up @@ -78,13 +78,13 @@ public class GraphQlRSocketHandler {
* followed by the given {@link ExecutionGraphQlService}.
*/
public GraphQlRSocketHandler(
ExecutionGraphQlService service, List<RSocketGraphQlHandlerInterceptor> interceptors) {
ExecutionGraphQlService service, List<RSocketGraphQlInterceptor> interceptors) {

Chain endOfChain = request -> service.execute(request).map(RSocketGraphQlResponse::new);

this.executionChain = (interceptors.isEmpty() ? endOfChain :
interceptors.stream()
.reduce(RSocketGraphQlHandlerInterceptor::andThen)
.reduce(RSocketGraphQlInterceptor::andThen)
.map(interceptor -> (Chain) request -> interceptor.intercept(request, endOfChain))
.orElse(endOfChain));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
* @author Rossen Stoyanchev
* @since 1.0.0
*/
public interface RSocketGraphQlHandlerInterceptor {
public interface RSocketGraphQlInterceptor {

/**
* Intercept a request and delegate to the rest of the chain including other
Expand All @@ -47,12 +47,12 @@ public interface RSocketGraphQlHandlerInterceptor {
Mono<RSocketGraphQlResponse> intercept(RSocketGraphQlRequest request, Chain chain);

/**
* Return a new {@link RSocketGraphQlHandlerInterceptor} that invokes the current
* Return a new {@link RSocketGraphQlInterceptor} that invokes the current
* interceptor first and then the one that is passed in.
* @param nextInterceptor the interceptor to delegate to after the current
* @return a new interceptor that chains the two
*/
default RSocketGraphQlHandlerInterceptor andThen(RSocketGraphQlHandlerInterceptor nextInterceptor) {
default RSocketGraphQlInterceptor andThen(RSocketGraphQlInterceptor nextInterceptor) {
return (request, chain) -> intercept(request, nextRequest -> nextInterceptor.intercept(nextRequest, chain));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ public interface WebGraphQlHandler {

/**
* Return the single interceptor of type
* {@link WebSocketGraphQlHandlerInterceptor} among all the configured
* {@link WebSocketGraphQlInterceptor} among all the configured
* interceptors.
*/
WebSocketGraphQlHandlerInterceptor webSocketInterceptor();
WebSocketGraphQlInterceptor webSocketInterceptor();


/**
Expand All @@ -62,7 +62,7 @@ static Builder builder(ExecutionGraphQlService graphQlService) {

/**
* Builder for a {@link WebGraphQlHandler} that executes a
* {@link WebGraphQlHandlerInterceptor} chain followed by a
* {@link WebGraphQlInterceptor} chain followed by a
* {@link ExecutionGraphQlService}.
*/
interface Builder {
Expand All @@ -71,22 +71,22 @@ interface Builder {
* Configure interceptors to be invoked before the target
* {@code GraphQlService}.
* <p>One of the interceptors can be of type
* {@link WebSocketGraphQlHandlerInterceptor} to handle data from the
* {@link WebSocketGraphQlInterceptor} 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(WebGraphQlHandlerInterceptor... interceptors);
Builder interceptor(WebGraphQlInterceptor... interceptors);

/**
* Alternative to {@link #interceptor(WebGraphQlHandlerInterceptor...)}
* Alternative to {@link #interceptor(WebGraphQlInterceptor...)}
* with a List.
* @param interceptors the list of interceptors to add
* @return this builder
*/
Builder interceptors(List<WebGraphQlHandlerInterceptor> interceptors);
Builder interceptors(List<WebGraphQlInterceptor> interceptors);

/**
* Configure accessors for ThreadLocal variables to use to extract
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@
*
* @author Rossen Stoyanchev
* @since 1.0.0
* @see WebSocketGraphQlHandlerInterceptor
* @see WebSocketGraphQlInterceptor
*/
public interface WebGraphQlHandlerInterceptor {
public interface WebGraphQlInterceptor {

/**
* Intercept a request and delegate to the rest of the chain including other
Expand All @@ -51,12 +51,12 @@ public interface WebGraphQlHandlerInterceptor {
Mono<WebGraphQlResponse> intercept(WebGraphQlRequest request, Chain chain);

/**
* Return a new {@link WebGraphQlHandlerInterceptor} that invokes the current
* Return a new {@link WebGraphQlInterceptor} that invokes the current
* interceptor first and then the one that is passed in.
* @param nextInterceptor the interceptor to delegate to after the current
* @return a new interceptor that chains the two
*/
default WebGraphQlHandlerInterceptor andThen(WebGraphQlHandlerInterceptor nextInterceptor) {
default WebGraphQlInterceptor andThen(WebGraphQlInterceptor nextInterceptor) {
return (request, chain) -> intercept(request, nextRequest -> nextInterceptor.intercept(nextRequest, chain));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@


/**
* An extension of {@link WebGraphQlHandlerInterceptor} with additional methods
* An extension of {@link WebGraphQlInterceptor} with additional methods
* to handle the start and end of a WebSocket connection. Only a single
* interceptor of type {@link WebSocketGraphQlHandlerInterceptor} may be
* interceptor of type {@link WebSocketGraphQlInterceptor} may be
* declared.
*
* @author Rossen Stoyanchev
* @since 1.0.0
*/
public interface WebSocketGraphQlHandlerInterceptor extends WebGraphQlHandlerInterceptor {
public interface WebSocketGraphQlInterceptor extends WebGraphQlInterceptor {

@Override
default Mono<WebGraphQlResponse> intercept(WebGraphQlRequest request, Chain chain) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* 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.WebGraphQlHandlerInterceptor interception}
* {@link org.springframework.graphql.web.WebGraphQlInterceptor interception}
* model that allows applications to customize the request and response.
*/
@NonNullApi
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
import org.springframework.graphql.web.WebGraphQlRequest;
import org.springframework.graphql.web.WebGraphQlHandler;
import org.springframework.graphql.web.WebGraphQlResponse;
import org.springframework.graphql.web.WebSocketGraphQlHandlerInterceptor;
import org.springframework.graphql.web.WebSocketGraphQlInterceptor;
import org.springframework.graphql.web.support.GraphQlMessage;
import org.springframework.http.codec.CodecConfigurer;
import org.springframework.util.Assert;
Expand Down Expand Up @@ -63,7 +63,7 @@ public class GraphQlWebSocketHandler implements WebSocketHandler {

private final WebGraphQlHandler graphQlHandler;

private final WebSocketGraphQlHandlerInterceptor webSocketInterceptor;
private final WebSocketGraphQlInterceptor webSocketInterceptor;

private final CodecDelegate codecDelegate;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
import org.springframework.graphql.web.WebGraphQlHandler;
import org.springframework.graphql.web.WebGraphQlRequest;
import org.springframework.graphql.web.WebGraphQlResponse;
import org.springframework.graphql.web.WebSocketGraphQlHandlerInterceptor;
import org.springframework.graphql.web.WebSocketGraphQlInterceptor;
import org.springframework.graphql.web.support.GraphQlMessage;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpInputMessage;
Expand Down Expand Up @@ -81,7 +81,7 @@ public class GraphQlWebSocketHandler extends TextWebSocketHandler implements Sub

private final WebGraphQlHandler graphQlHandler;

private final WebSocketGraphQlHandlerInterceptor webSocketInterceptor;
private final WebSocketGraphQlInterceptor webSocketInterceptor;

private final Duration initTimeoutDuration;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
import org.springframework.graphql.web.TestWebSocketClient;
import org.springframework.graphql.web.TestWebSocketConnection;
import org.springframework.graphql.web.WebGraphQlHandler;
import org.springframework.graphql.web.WebGraphQlHandlerInterceptor;
import org.springframework.graphql.web.WebGraphQlInterceptor;
import org.springframework.graphql.web.webflux.GraphQlHttpHandler;
import org.springframework.graphql.web.webflux.GraphQlWebSocketHandler;
import org.springframework.http.codec.ClientCodecConfigurer;
Expand All @@ -63,7 +63,7 @@

/**
* Tests for the builders of Web {@code GraphQlClient} extensions, using a
* {@link WebGraphQlHandlerInterceptor} to capture the WebInput on the server
* {@link WebGraphQlInterceptor} to capture the WebInput on the server
* side, and optionally returning a mock response, or an empty response.
*
* <ul>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

public class ConsumeOneAndNeverCompleteInterceptor implements WebGraphQlHandlerInterceptor {
public class ConsumeOneAndNeverCompleteInterceptor implements WebGraphQlInterceptor {

@Override
public Mono<WebGraphQlResponse> intercept(WebGraphQlRequest request, Chain chain) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@
import static org.assertj.core.api.Assertions.assertThat;

/**
* Unit tests for a {@link WebGraphQlHandlerInterceptor} chain.
* Unit tests for a {@link WebGraphQlInterceptor} chain.
*/
public class WebGraphQlHandlerInterceptorTests {
public class WebGraphQlInterceptorTests {

private static final WebGraphQlRequest webRequest = new WebGraphQlRequest(
URI.create("http://abc.org"), new HttpHeaders(), Collections.singletonMap("query", "{ notUsed }"), "1", null);
Expand Down Expand Up @@ -98,7 +98,7 @@ private Mono<ExecutionGraphQlResponse> emptyExecutionResult(ExecutionGraphQlRequ
ExecutionResultImpl.newExecutionResult().build()));
}

private static class OrderInterceptor implements WebGraphQlHandlerInterceptor {
private static class OrderInterceptor implements WebGraphQlInterceptor {

private final StringBuilder sb;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public abstract class WebSocketHandlerTestSupport {
"}";


protected WebGraphQlHandler initHandler(WebGraphQlHandlerInterceptor... interceptors) {
protected WebGraphQlHandler initHandler(WebGraphQlInterceptor... interceptors) {
return GraphQlSetup.schemaResource(BookSource.schema)
.queryFetcher("bookById", environment -> {
Long id = Long.parseLong(environment.getArgument("id"));
Expand Down
Loading

0 comments on commit 6584b88

Please sign in to comment.