From 7edc2d9ce62fa9482bc6b6748d0a431ebffbf90f Mon Sep 17 00:00:00 2001 From: Andreas Marek Date: Sun, 9 Aug 2020 16:34:51 +1000 Subject: [PATCH] use configuration annotation --- .../reactive/components/GraphQLController.java | 4 ++-- .../servlet/components/GraphQLController.java | 14 ++++++++------ 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/spring-graphql-webflux/src/main/java/org/springframework/graphql/reactive/components/GraphQLController.java b/spring-graphql-webflux/src/main/java/org/springframework/graphql/reactive/components/GraphQLController.java index 5492a887..68f8caba 100644 --- a/spring-graphql-webflux/src/main/java/org/springframework/graphql/reactive/components/GraphQLController.java +++ b/spring-graphql-webflux/src/main/java/org/springframework/graphql/reactive/components/GraphQLController.java @@ -3,8 +3,8 @@ package org.springframework.graphql.reactive.components; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; import org.springframework.graphql.reactive.GraphQLInvocationData; -import org.springframework.stereotype.Component; import org.springframework.web.reactive.function.server.RouterFunction; import org.springframework.web.reactive.function.server.ServerRequest; import org.springframework.web.reactive.function.server.ServerResponse; @@ -14,7 +14,7 @@ import java.util.Map; import static org.springframework.web.reactive.function.server.RouterFunctions.route; -@Component +@Configuration public class GraphQLController { @Autowired diff --git a/spring-graphql-webmvc/src/main/java/org/springframework/graphql/servlet/components/GraphQLController.java b/spring-graphql-webmvc/src/main/java/org/springframework/graphql/servlet/components/GraphQLController.java index 5e353b26..7baae1c8 100644 --- a/spring-graphql-webmvc/src/main/java/org/springframework/graphql/servlet/components/GraphQLController.java +++ b/spring-graphql-webmvc/src/main/java/org/springframework/graphql/servlet/components/GraphQLController.java @@ -3,17 +3,20 @@ package org.springframework.graphql.servlet.components; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; import org.springframework.graphql.servlet.GraphQLInvocationData; -import org.springframework.stereotype.Component; +import org.springframework.http.MediaType; +import org.springframework.web.servlet.function.RequestPredicates; import org.springframework.web.servlet.function.RouterFunction; import org.springframework.web.servlet.function.ServerRequest; import org.springframework.web.servlet.function.ServerResponse; +import javax.servlet.ServletException; import java.io.IOException; import static org.springframework.web.servlet.function.RouterFunctions.route; -@Component +@Configuration public class GraphQLController { @Autowired @@ -22,7 +25,8 @@ public class GraphQLController { @Bean public RouterFunction routerFunction() { RouterFunction route = route() - .POST("/graphql", this::graphqlPOST) + .POST("/graphql", RequestPredicates.contentType(MediaType.APPLICATION_JSON) + .or(RequestPredicates.contentType(MediaType.APPLICATION_JSON_UTF8)), this::graphqlPOST) .build(); return route; @@ -32,9 +36,7 @@ public class GraphQLController { GraphQLRequestBody body = null; try { body = serverRequest.body(GraphQLRequestBody.class); - } catch (javax.servlet.ServletException e) { - e.printStackTrace(); - } catch (IOException e) { + } catch (ServletException | IOException e) { e.printStackTrace(); } String query = body.getQuery();