### Question:
GraphqlServlet extends SlingAllMethodsServlet { @SuppressWarnings("unchecked") @Override protected void doPost(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException { String body = IOUtils.toString(request.getReader()); Type type = TypeToken.getParameterized(GraphqlRequest.class, Query.class, Error.class).getType(); GraphqlRequest graphqlRequest = gson.fromJson(body, type); Map<String, Object> vars = null; if (graphqlRequest.getVariables() != null) { vars = (Map<String, Object>) graphqlRequest.getVariables(); } ExecutionResult executionResult = execute(graphqlRequest.getQuery(), graphqlRequest.getOperationName(), vars); writeResponse(executionResult, response); }  @Override void init();  }### Answer:
@Test public void testPostRequestWithVariables() throws ServletException, IOException { String query = "query rootCategory($catId: Int!) {category(id: $catId){id,name,url_path}}"; GraphqlRequest graphqlRequest = new GraphqlRequest(query); graphqlRequest.setVariables(Collections.singletonMap("catId", 2)); graphqlRequest.setOperationName("rootCategory"); String body = QueryDeserializer.getGson().toJson(graphqlRequest); request.setContent(body.getBytes()); graphqlServlet.doPost(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()); }