diff --git a/spring-graphql-web/src/main/java/org/springframework/boot/graphql/WebFluxGraphQLAutoConfiguration.java b/spring-graphql-web/src/main/java/org/springframework/boot/graphql/WebFluxGraphQLAutoConfiguration.java index 63187d5..2e68cf1 100644 --- a/spring-graphql-web/src/main/java/org/springframework/boot/graphql/WebFluxGraphQLAutoConfiguration.java +++ b/spring-graphql-web/src/main/java/org/springframework/boot/graphql/WebFluxGraphQLAutoConfiguration.java @@ -26,6 +26,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.core.io.ResourceLoader; import org.springframework.graphql.WebFluxGraphQLHandler; import org.springframework.http.MediaType; import org.springframework.web.reactive.function.server.RouterFunction; @@ -33,6 +34,7 @@ import org.springframework.web.reactive.function.server.ServerResponse; import static org.springframework.web.reactive.function.server.RequestPredicates.accept; +import static org.springframework.web.reactive.function.server.RequestPredicates.contentType; @Configuration @ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.REACTIVE) @@ -48,8 +50,12 @@ public WebFluxGraphQLHandler graphQLHandler(GraphQL.Builder graphQLBuilder) { } @Bean - public RouterFunction graphQLQueryEndpoint(WebFluxGraphQLHandler handler, GraphQLProperties graphQLProperties) { - return RouterFunctions.route().POST(graphQLProperties.getPath(), accept(MediaType.APPLICATION_JSON), handler).build(); + public RouterFunction graphQLQueryEndpoint(ResourceLoader resourceLoader, WebFluxGraphQLHandler handler, + GraphQLProperties graphQLProperties) { + return RouterFunctions.route() + .GET(graphQLProperties.getPath(), req -> ServerResponse.ok().bodyValue(resourceLoader.getResource("classpath:graphiql/index.html"))) + .POST(graphQLProperties.getPath(), accept(MediaType.APPLICATION_JSON).and(contentType(MediaType.APPLICATION_JSON)), handler) + .build(); } } diff --git a/spring-graphql-web/src/main/java/org/springframework/boot/graphql/WebMvcGraphQLAutoConfiguration.java b/spring-graphql-web/src/main/java/org/springframework/boot/graphql/WebMvcGraphQLAutoConfiguration.java index ea498b8..0a8ec09 100644 --- a/spring-graphql-web/src/main/java/org/springframework/boot/graphql/WebMvcGraphQLAutoConfiguration.java +++ b/spring-graphql-web/src/main/java/org/springframework/boot/graphql/WebMvcGraphQLAutoConfiguration.java @@ -26,6 +26,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.core.io.ResourceLoader; import org.springframework.graphql.WebMvcGraphQLHandler; import org.springframework.http.MediaType; import org.springframework.web.servlet.function.RouterFunction; @@ -33,9 +34,10 @@ import org.springframework.web.servlet.function.ServerResponse; import static org.springframework.web.servlet.function.RequestPredicates.accept; +import static org.springframework.web.servlet.function.RequestPredicates.contentType; @Configuration -@ConditionalOnWebApplication +@ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.SERVLET) @ConditionalOnClass(GraphQL.class) @ConditionalOnBean(GraphQL.Builder.class) @AutoConfigureAfter(GraphQLAutoConfiguration.class) @@ -48,9 +50,11 @@ public WebMvcGraphQLHandler graphQLHandler(GraphQL.Builder graphQLBuilder) { } @Bean - public RouterFunction graphQLQueryEndpoint(WebMvcGraphQLHandler handler, GraphQLProperties graphQLProperties) { + public RouterFunction graphQLQueryEndpoint(ResourceLoader resourceLoader, WebMvcGraphQLHandler handler, + GraphQLProperties graphQLProperties) { return RouterFunctions.route() - .POST(graphQLProperties.getPath(), accept(MediaType.APPLICATION_JSON), handler) + .GET(graphQLProperties.getPath(), req -> ServerResponse.ok().body(resourceLoader.getResource("classpath:graphiql/index.html"))) + .POST(graphQLProperties.getPath(), contentType(MediaType.APPLICATION_JSON).and(accept(MediaType.APPLICATION_JSON)), handler) .build(); } diff --git a/spring-graphql-web/src/main/resources/META-INF/spring-devtools.properties b/spring-graphql-web/src/main/resources/META-INF/spring-devtools.properties new file mode 100644 index 0000000..cf65371 --- /dev/null +++ b/spring-graphql-web/src/main/resources/META-INF/spring-devtools.properties @@ -0,0 +1 @@ +restart.include.graphql-java=graphql-java.*\.jar \ No newline at end of file diff --git a/spring-graphql-web/src/main/resources/graphiql/index.html b/spring-graphql-web/src/main/resources/graphiql/index.html new file mode 100644 index 0000000..cc0d57d --- /dev/null +++ b/spring-graphql-web/src/main/resources/graphiql/index.html @@ -0,0 +1,92 @@ + + + + + + + + + + + + + + + +
Loading...
+ + + + +