|
6 | 6 | import java.util.Collections; |
7 | 7 | import java.util.HashMap; |
8 | 8 | import java.util.Map; |
9 | | -import java.util.Optional; |
10 | 9 |
|
11 | 10 | /** |
12 | 11 | * Graphql clients can send GET or POST HTTP requests. The spec does not make an explicit |
@@ -42,43 +41,20 @@ public Map<String, Object> getVariables() { |
42 | 41 | static QueryParameters from(HttpServletRequest request) { |
43 | 42 | QueryParameters parameters = new QueryParameters(); |
44 | 43 | if ("POST".equalsIgnoreCase(request.getMethod())) { |
45 | | - // |
46 | | - // the graphql guidance says : |
47 | | - // |
48 | | - // If the "application/graphql" Content-Type header is present, treat |
49 | | - // the HTTP POST body contents as the GraphQL query string. |
50 | | - if ("application/graphql".equals(request.getContentType())) { |
51 | | - parameters.query = readPostBody(request); |
52 | | - } else { |
53 | | - Map<String, Object> json = readJSON(request); |
54 | | - |
55 | | - // |
56 | | - // the graphql guidance says : |
57 | | - // |
58 | | - // - If the "query" query string parameter is present |
59 | | - // - ..., it should be parsed and handled |
60 | | - // - in the same way as the HTTP GET case. |
61 | | - // |
62 | | - Optional<String> queryStr = getQueryQueryParameter(request); |
63 | | - parameters.query = queryStr.orElseGet(() -> (String) json.get("query")); |
64 | | - parameters.operationName = (String) json.get("operationName"); |
65 | | - parameters.variables = getVariablesFromPost(json.get("variables")); |
66 | | - } |
| 44 | + Map<String, Object> json = readJSON(request); |
| 45 | + parameters.query = (String) json.get("query"); |
| 46 | + parameters.operationName = (String) json.get("operationName"); |
| 47 | + parameters.variables = getVariables(json.get("variables")); |
67 | 48 | } else { |
68 | 49 | parameters.query = request.getParameter("query"); |
69 | 50 | parameters.operationName = request.getParameter("operationName"); |
70 | | - parameters.variables = getVariablesFromPost(request.getParameter("variables")); |
| 51 | + parameters.variables = getVariables(request.getParameter("variables")); |
71 | 52 | } |
72 | 53 | return parameters; |
73 | 54 | } |
74 | 55 |
|
75 | | - private static Optional<String> getQueryQueryParameter(HttpServletRequest request) { |
76 | | - // http servlet spec getParameter() does not distinguish between POST body or GET query strings |
77 | | - // so we have to parse for it in this case |
78 | | - return HttpKit.getQueryParameter(request,"query"); |
79 | | - } |
80 | 56 |
|
81 | | - private static Map<String, Object> getVariablesFromPost(Object variables) { |
| 57 | + private static Map<String, Object> getVariables(Object variables) { |
82 | 58 | if (variables instanceof Map) { |
83 | 59 | Map<?, ?> inputVars = (Map) variables; |
84 | 60 | Map<String, Object> vars = new HashMap<>(); |
|
0 commit comments