Turn off auto-formatting where it reduces readability

This commit is contained in:
Rossen Stoyanchev
2021-06-15 14:01:52 +01:00
parent a5f56ca3cb
commit 43f9e34c81
27 changed files with 534 additions and 283 deletions

View File

@@ -45,13 +45,15 @@ import org.springframework.graphql.web.webflux.GraphQlWebSocketHandler;
import org.springframework.http.MediaType;
import org.springframework.http.codec.ServerCodecConfigurer;
import org.springframework.web.reactive.HandlerMapping;
import org.springframework.web.reactive.function.server.RequestPredicates;
import org.springframework.web.reactive.function.server.RouterFunction;
import org.springframework.web.reactive.function.server.RouterFunctions;
import org.springframework.web.reactive.function.server.ServerResponse;
import org.springframework.web.reactive.handler.SimpleUrlHandlerMapping;
import org.springframework.web.reactive.socket.server.support.WebSocketUpgradeHandlerPredicate;
import static org.springframework.web.reactive.function.server.RequestPredicates.accept;
import static org.springframework.web.reactive.function.server.RequestPredicates.contentType;
/**
* {@link EnableAutoConfiguration Auto-configuration} for enabling Spring GraphQL over
* WebFlux.
@@ -90,15 +92,18 @@ public class WebFluxGraphQlAutoConfiguration {
if (logger.isInfoEnabled()) {
logger.info("GraphQL endpoint HTTP POST " + path);
}
// @formatter:off
RouterFunctions.Builder builder = RouterFunctions.route()
.GET(path, (req) -> ServerResponse.ok().bodyValue(resource))
.POST(path, RequestPredicates.accept(MediaType.APPLICATION_JSON)
.and(RequestPredicates.contentType(MediaType.APPLICATION_JSON)), handler::handleRequest);
.POST(path, accept(MediaType.APPLICATION_JSON).and(contentType(MediaType.APPLICATION_JSON)), handler::handleRequest);
if (properties.getSchema().getPrinter().isEnabled()) {
SchemaPrinter printer = new SchemaPrinter();
builder = builder.GET(path + properties.getSchema().getPrinter().getPath(), (req) -> ServerResponse.ok()
.contentType(MediaType.TEXT_PLAIN).bodyValue(printer.print(graphQlSource.schema())));
builder = builder.GET(path + properties.getSchema().getPrinter().getPath(),
(req) -> ServerResponse.ok()
.contentType(MediaType.TEXT_PLAIN)
.bodyValue(printer.print(graphQlSource.schema())));
}
// @formatter:on
return builder.build();
}

View File

@@ -50,7 +50,6 @@ import org.springframework.graphql.web.webmvc.GraphQlWebSocketHandler;
import org.springframework.http.MediaType;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.web.servlet.HandlerMapping;
import org.springframework.web.servlet.function.RequestPredicates;
import org.springframework.web.servlet.function.RouterFunction;
import org.springframework.web.servlet.function.RouterFunctions;
import org.springframework.web.servlet.function.ServerResponse;
@@ -59,6 +58,9 @@ import org.springframework.web.socket.server.support.DefaultHandshakeHandler;
import org.springframework.web.socket.server.support.WebSocketHandlerMapping;
import org.springframework.web.socket.server.support.WebSocketHttpRequestHandler;
import static org.springframework.web.servlet.function.RequestPredicates.accept;
import static org.springframework.web.servlet.function.RequestPredicates.contentType;
/**
* {@link EnableAutoConfiguration Auto-configuration} for enabling Spring GraphQL over
* Spring MVC.
@@ -100,14 +102,18 @@ public class WebMvcGraphQlAutoConfiguration {
if (logger.isInfoEnabled()) {
logger.info("GraphQL endpoint HTTP POST " + path);
}
RouterFunctions.Builder builder = RouterFunctions.route().GET(path, (req) -> ServerResponse.ok().body(resource))
.POST(path, RequestPredicates.contentType(MediaType.APPLICATION_JSON)
.and(RequestPredicates.accept(MediaType.APPLICATION_JSON)), handler::handleRequest);
// @formatter:off
RouterFunctions.Builder builder = RouterFunctions.route()
.GET(path, (req) -> ServerResponse.ok().body(resource))
.POST(path, contentType(MediaType.APPLICATION_JSON).and(accept(MediaType.APPLICATION_JSON)), handler::handleRequest);
if (properties.getSchema().getPrinter().isEnabled()) {
SchemaPrinter printer = new SchemaPrinter();
builder = builder.GET(path + properties.getSchema().getPrinter().getPath(), (req) -> ServerResponse.ok()
.contentType(MediaType.TEXT_PLAIN).body(printer.print(graphQlSource.schema())));
builder = builder.GET(path + properties.getSchema().getPrinter().getPath(),
(req) -> ServerResponse.ok()
.contentType(MediaType.TEXT_PLAIN)
.body(printer.print(graphQlSource.schema())));
}
// @formatter:on
return builder.build();
}
@@ -121,9 +127,12 @@ public class WebMvcGraphQlAutoConfiguration {
public GraphQlWebSocketHandler graphQlWebSocketHandler(WebGraphQlHandler webGraphQlHandler,
GraphQlProperties properties, HttpMessageConverters converters) {
// @formatter:off
HttpMessageConverter<?> converter = converters.getConverters().stream()
.filter((candidate) -> candidate.canRead(Map.class, MediaType.APPLICATION_JSON)).findFirst()
.filter((candidate) -> candidate.canRead(Map.class, MediaType.APPLICATION_JSON))
.findFirst()
.orElseThrow(() -> new IllegalStateException("No JSON converter"));
// @formatter:on
return new GraphQlWebSocketHandler(webGraphQlHandler, converter,
properties.getWebsocket().getConnectionInitTimeout());