Skip to content

Commit

Permalink
Make url configurable and set default to /graphql
Browse files Browse the repository at this point in the history
  • Loading branch information
andimarek authored and bclozel committed Oct 13, 2020
1 parent 7eafec2 commit d0324b8
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
*/
package org.springframework.boot.graphql;

import java.util.Collections;

import graphql.GraphQL;

import org.springframework.boot.autoconfigure.AutoConfigureAfter;
Expand All @@ -31,6 +29,8 @@
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)
Expand All @@ -45,8 +45,8 @@ public WebFluxGraphQLHandler graphQLHandler(GraphQL.Builder graphQLBuilder) {
}

@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();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
*/
package org.springframework.boot.graphql;

import java.util.Collections;

import graphql.GraphQL;

import org.springframework.boot.autoconfigure.AutoConfigureAfter;
Expand All @@ -32,6 +30,8 @@
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
Expand All @@ -48,9 +48,9 @@ public WebMvcGraphQLHandler graphQLHandler(GraphQL.Builder graphQLBuilder) {
}

@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();
}

Expand Down

0 comments on commit d0324b8

Please sign in to comment.