use configuration annotation

This commit is contained in:
Andreas Marek
2020-08-09 16:34:51 +10:00
committed by Rossen Stoyanchev
parent 11d2ad74cf
commit 7edc2d9ce6
2 changed files with 10 additions and 8 deletions

View File

@@ -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

View File

@@ -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<ServerResponse> routerFunction() {
RouterFunction<ServerResponse> 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();