Skip to content

Commit

Permalink
Voyager controllers replaced with RouterFunctions and common RouterFu…
Browse files Browse the repository at this point in the history
…nctions refactoring
  • Loading branch information
sadv1r authored May 30, 2024
1 parent 0eeb7cf commit f6489bb
Show file tree
Hide file tree
Showing 13 changed files with 164 additions and 187 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package ru.sadv1r.spring.graphql.editor.graphiql.configuration;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.core.annotation.Order;
import org.springframework.web.reactive.function.server.HandlerFunction;
import org.springframework.web.reactive.function.server.RenderingResponse;
import org.springframework.web.reactive.function.server.RouterFunction;
import org.springframework.web.reactive.function.server.RouterFunctions;

import static org.springframework.web.reactive.function.server.RequestPredicates.GET;

@AutoConfiguration
@EnableConfigurationProperties(GraphiqlProperties.class)
@ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.REACTIVE)
@ConditionalOnProperty(value = "spring.graphql.graphiql.enabled", havingValue = "true", matchIfMissing = true)
public class GraphiQlWebFluxAutoConfiguration {

@Bean
@Order(-1)
public RouterFunction<RenderingResponse> reactiveGraphiQlRouterFunction(GraphiqlProperties properties,
@Value("${spring.graphql.path:/graphql}") String serverPath) {
final HandlerFunction<RenderingResponse> handler = e -> RenderingResponse.create("graphiql")
.modelAttribute("cdnHost", properties.getCdn().getHost())
.modelAttribute("serverPath", serverPath)
.modelAttribute("query", properties.getQuery())
.modelAttribute("defaultEditorToolsVisibility", properties.getDefaultEditorToolsVisibility())
.modelAttribute("variables", properties.getVariables())
.modelAttribute("headers", properties.getHeaders())
.modelAttribute("plugins", properties.getPlugins())
.modelAttribute("stylePath", properties.getStylePath())
.build();

return RouterFunctions.route(GET(properties.getPath()), handler);
}

}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import org.springframework.core.annotation.Order;
import org.springframework.web.servlet.function.*;

import static org.springframework.web.servlet.function.RequestPredicates.GET;

@AutoConfiguration
@EnableConfigurationProperties(GraphiqlProperties.class)
@ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.SERVLET)
Expand All @@ -19,21 +21,18 @@ public class GraphiQlWebMvcAutoConfiguration {
@Order(-1)
public RouterFunction<ServerResponse> graphiQlRouterFunction(GraphiqlProperties properties,
@Value("${spring.graphql.path:/graphql}") String serverPath) {
RouterFunctions.Builder builder = RouterFunctions.route();
if (properties.isEnabled()) {
final HandlerFunction<ServerResponse> graphiql = e -> RenderingResponse.create("graphiql")
.modelAttribute("cdnHost", properties.getCdn().getHost())
.modelAttribute("serverPath", serverPath)
.modelAttribute("query", properties.getQuery())
.modelAttribute("defaultEditorToolsVisibility", properties.getDefaultEditorToolsVisibility())
.modelAttribute("variables", properties.getVariables())
.modelAttribute("headers", properties.getHeaders())
.modelAttribute("plugins", properties.getPlugins())
.modelAttribute("stylePath", properties.getStylePath())
.build();
builder = builder.GET(properties.getPath(), graphiql);
}
return builder.build();
final HandlerFunction<ServerResponse> handler = e -> RenderingResponse.create("graphiql")
.modelAttribute("cdnHost", properties.getCdn().getHost())
.modelAttribute("serverPath", serverPath)
.modelAttribute("query", properties.getQuery())
.modelAttribute("defaultEditorToolsVisibility", properties.getDefaultEditorToolsVisibility())
.modelAttribute("variables", properties.getVariables())
.modelAttribute("headers", properties.getHeaders())
.modelAttribute("plugins", properties.getPlugins())
.modelAttribute("stylePath", properties.getStylePath())
.build();

return RouterFunctions.route(GET(properties.getPath()), handler);
}

}
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
ru.sadv1r.spring.graphql.editor.graphiql.configuration.GraphiQlWebFluxMvcAutoConfiguration
ru.sadv1r.spring.graphql.editor.graphiql.configuration.GraphiQlWebFluxAutoConfiguration
ru.sadv1r.spring.graphql.editor.graphiql.configuration.GraphiQlWebMvcAutoConfiguration
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.core.annotation.Order;
import org.springframework.web.reactive.function.server.*;
import reactor.core.publisher.Mono;
import org.springframework.web.reactive.function.server.HandlerFunction;
import org.springframework.web.reactive.function.server.RenderingResponse;
import org.springframework.web.reactive.function.server.RouterFunction;
import org.springframework.web.reactive.function.server.RouterFunctions;

import static org.springframework.web.reactive.function.server.RequestPredicates.GET;

@AutoConfiguration
@EnableConfigurationProperties(PlaygroundProperties.class)
Expand All @@ -18,21 +22,17 @@ public class PlaygroundWebFluxMvcAutoConfiguration {

@Bean
@Order(-1)
@ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.REACTIVE)
public RouterFunction<ServerResponse> reactivePlaygroundRouterFunction(PlaygroundProperties properties,
@Value("${spring.graphql.path:/graphql}") String serverPath) {
RouterFunctions.Builder builder = RouterFunctions.route();
if (properties.isEnabled()) {
final HandlerFunction<ServerResponse> handler = e -> (Mono<ServerResponse>) (Mono<?>) RenderingResponse.create("playground")
.modelAttribute("cdnHost", properties.getCdn().getHost())
.modelAttribute("serverPath", serverPath)
.modelAttribute("settings", properties.getSettings())
.modelAttribute("headers", properties.getHeaders())
.modelAttribute("tabs", properties.getTabs())
.build();
builder = builder.GET(properties.getPath(), handler);
}
return builder.build();
public RouterFunction<RenderingResponse> reactivePlaygroundRouterFunction(PlaygroundProperties properties,
@Value("${spring.graphql.path:/graphql}") String serverPath) {
final HandlerFunction<RenderingResponse> handler = e -> RenderingResponse.create("playground")
.modelAttribute("cdnHost", properties.getCdn().getHost())
.modelAttribute("serverPath", serverPath)
.modelAttribute("settings", properties.getSettings())
.modelAttribute("headers", properties.getHeaders())
.modelAttribute("tabs", properties.getTabs())
.build();

return RouterFunctions.route(GET(properties.getPath()), handler);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import org.springframework.core.annotation.Order;
import org.springframework.web.servlet.function.*;

import static org.springframework.web.servlet.function.RequestPredicates.GET;

@AutoConfiguration
@EnableConfigurationProperties(PlaygroundProperties.class)
@ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.SERVLET)
Expand All @@ -18,19 +20,16 @@ public class PlaygroundWebMvcAutoConfiguration {
@Bean
@Order(-1)
public RouterFunction<ServerResponse> playgroundRouterFunction(PlaygroundProperties properties,
@Value("${spring.graphql.path:/graphql}") String serverPath) {
RouterFunctions.Builder builder = RouterFunctions.route();
if (properties.isEnabled()) {
final HandlerFunction<ServerResponse> handler = e -> RenderingResponse.create("playground")
.modelAttribute("cdnHost", properties.getCdn().getHost())
.modelAttribute("serverPath", serverPath)
.modelAttribute("settings", properties.getSettings())
.modelAttribute("headers", properties.getHeaders())
.modelAttribute("tabs", properties.getTabs())
.build();
builder = builder.GET(properties.getPath(), handler);
}
return builder.build();
@Value("${spring.graphql.path:/graphql}") String serverPath) {
final HandlerFunction<ServerResponse> handler = e -> RenderingResponse.create("playground")
.modelAttribute("cdnHost", properties.getCdn().getHost())
.modelAttribute("serverPath", serverPath)
.modelAttribute("settings", properties.getSettings())
.modelAttribute("headers", properties.getHeaders())
.modelAttribute("tabs", properties.getTabs())
.build();

return RouterFunctions.route(GET(properties.getPath()), handler);
}

}

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package ru.sadv1r.spring.graphql.editor.voyager.configuration;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.core.annotation.Order;
import org.springframework.web.reactive.function.server.HandlerFunction;
import org.springframework.web.reactive.function.server.RenderingResponse;
import org.springframework.web.reactive.function.server.RouterFunction;
import org.springframework.web.reactive.function.server.RouterFunctions;

import static org.springframework.web.reactive.function.server.RequestPredicates.GET;

@AutoConfiguration
@EnableConfigurationProperties(VoyagerProperties.class)
@ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.REACTIVE)
@ConditionalOnProperty(value = "spring.graphql.voyager.enabled", havingValue = "true", matchIfMissing = true)
public class VoyagerWebFluxAutoConfiguration {

@Bean
@Order(-1)
public RouterFunction<RenderingResponse> reactiveVoyagerRouterFunction(VoyagerProperties properties,
@Value("${spring.graphql.path:/graphql}") String serverPath) {
final HandlerFunction<RenderingResponse> handler = e -> RenderingResponse.create("voyager")
.modelAttribute("cdnHost", properties.getCdn().getHost())
.modelAttribute("serverPath", serverPath)
.modelAttribute("displayOptions", properties.getDisplayOptions())
.modelAttribute("hideDocs", properties.isHideDocs())
.modelAttribute("hideSettings", properties.isHideSettings())
.modelAttribute("stylePath", properties.getStylePath())
.build();

return RouterFunctions.route(GET(properties.getPath()), handler);
}

}
Loading

0 comments on commit f6489bb

Please sign in to comment.