@Test public void testGetRequestWithVariables() throws ServletException, IOException { String query = "query rootCategory($catId: Int!) {category(id: $catId){id,name,url_path}}"; Map<String, Object> params = new HashMap<>(); params.put("query", query); params.put("variables", Collections.singletonMap("catId", 2)); params.put("operationName", "rootCategory"); request.setParameterMap(params); graphqlServlet.doGet(request, response); String output = response.getOutputAsString(); Type type = TypeToken.getParameterized(GraphqlResponse.class, Query.class, Error.class).getType(); GraphqlResponse<Query, Error> graphqlResponse = QueryDeserializer.getGson().fromJson(output, type); CategoryTree category = graphqlResponse.getData().getCategory(); Assert.assertEquals(2, category.getId().intValue()); }
@Override protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException { String query = request.getParameter(QUERY_PARAMETER); String operationName = request.getParameter(OPERATION_NAME_PARAMETER); String variables = request.getParameter(VARIABLES_PARAMETER); Map<String, Object> vars = null; if (StringUtils.isNotBlank(variables)) { Type type = TypeToken.getParameterized(Map.class, String.class, Object.class).getType(); vars = gson.fromJson(variables, type); } ExecutionResult executionResult = execute(query, operationName, vars); writeResponse(executionResult, response); }
GraphqlServlet extends SlingAllMethodsServlet { @Override protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException { String query = request.getParameter(QUERY_PARAMETER); String operationName = request.getParameter(OPERATION_NAME_PARAMETER); String variables = request.getParameter(VARIABLES_PARAMETER); Map<String, Object> vars = null; if (StringUtils.isNotBlank(variables)) { Type type = TypeToken.getParameterized(Map.class, String.class, Object.class).getType(); vars = gson.fromJson(variables, type); } ExecutionResult executionResult = execute(query, operationName, vars); writeResponse(executionResult, response); } }
GraphqlServlet extends SlingAllMethodsServlet { @Override protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException { String query = request.getParameter(QUERY_PARAMETER); String operationName = request.getParameter(OPERATION_NAME_PARAMETER); String variables = request.getParameter(VARIABLES_PARAMETER); Map<String, Object> vars = null; if (StringUtils.isNotBlank(variables)) { Type type = TypeToken.getParameterized(Map.class, String.class, Object.class).getType(); vars = gson.fromJson(variables, type); } ExecutionResult executionResult = execute(query, operationName, vars); writeResponse(executionResult, response); }  }
GraphqlServlet extends SlingAllMethodsServlet { @Override protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException { String query = request.getParameter(QUERY_PARAMETER); String operationName = request.getParameter(OPERATION_NAME_PARAMETER); String variables = request.getParameter(VARIABLES_PARAMETER); Map<String, Object> vars = null; if (StringUtils.isNotBlank(variables)) { Type type = TypeToken.getParameterized(Map.class, String.class, Object.class).getType(); vars = gson.fromJson(variables, type); } ExecutionResult executionResult = execute(query, operationName, vars); writeResponse(executionResult, response); }  @Override void init(); }
GraphqlServlet extends SlingAllMethodsServlet { @Override protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException { String query = request.getParameter(QUERY_PARAMETER); String operationName = request.getParameter(OPERATION_NAME_PARAMETER); String variables = request.getParameter(VARIABLES_PARAMETER); Map<String, Object> vars = null; if (StringUtils.isNotBlank(variables)) { Type type = TypeToken.getParameterized(Map.class, String.class, Object.class).getType(); vars = gson.fromJson(variables, type); } ExecutionResult executionResult = execute(query, operationName, vars); writeResponse(executionResult, response); }  @Override void init();  }