Make url configurable and set default to /graphql

Closes gh-9
This commit is contained in:
Andreas Marek
2020-10-11 18:11:30 +11:00
committed by Brian Clozel
parent 7eafec25e3
commit d0324b8344
3 changed files with 18 additions and 8 deletions

View File

@@ -22,6 +22,16 @@ public class GraphQLProperties {
private String schema = "classpath:schema.graphqls";
private String url = "/graphql";
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public String getSchema() {
return schema;
}

View File

@@ -15,8 +15,6 @@
*/
package org.springframework.boot.graphql;
import java.util.Collections;
import graphql.GraphQL;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
@@ -31,6 +29,8 @@ 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 java.util.Collections;
@Configuration
@ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.REACTIVE)
@ConditionalOnClass(GraphQL.class)
@@ -45,8 +45,8 @@ public class WebFluxGraphQLAutoConfiguration {
}
@Bean
public RouterFunction<ServerResponse> graphQLQueryEndpoint(WebFluxGraphQLHandler handler) {
return RouterFunctions.route().POST("/graphql", handler).build();
public RouterFunction<ServerResponse> graphQLQueryEndpoint(WebFluxGraphQLHandler handler, GraphQLProperties graphQLProperties) {
return RouterFunctions.route().POST(graphQLProperties.getUrl(), handler).build();
}
}

View File

@@ -15,8 +15,6 @@
*/
package org.springframework.boot.graphql;
import java.util.Collections;
import graphql.GraphQL;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
@@ -32,6 +30,8 @@ import org.springframework.web.servlet.function.RouterFunction;
import org.springframework.web.servlet.function.RouterFunctions;
import org.springframework.web.servlet.function.ServerResponse;
import java.util.Collections;
import static org.springframework.web.servlet.function.RequestPredicates.accept;
@Configuration
@@ -48,9 +48,9 @@ public class WebMvcGraphQLAutoConfiguration {
}
@Bean
public RouterFunction<ServerResponse> graphQLQueryEndpoint(WebMvcGraphQLHandler handler) {
public RouterFunction<ServerResponse> graphQLQueryEndpoint(WebMvcGraphQLHandler handler, GraphQLProperties graphQLProperties) {
return RouterFunctions.route()
.POST("/graphql", accept(MediaType.APPLICATION_JSON), handler)
.POST(graphQLProperties.getUrl(), accept(MediaType.APPLICATION_JSON), handler)
.build();
}