thanks
Peace.
Spark.post("/query", (req, res) -> {
JSONObject query = new JSONObject(req.body()); // parse the complete request body, maybe you should print out the plain request to understand the GraphiQL query structrue
if (query.has("query") && query.getString("query").indexOf("IntrospectionQuery") != -1) {
String introSpection = query.getString("query");
Map<String, Object> result = new HashMap<>();
result.put("data", graphQLService.query(introSpection)); // you have to wrap it into a data json key!
return new JSONObject(result);
}
JSONObject queryResult = new JSONObject(graphQLService.query(query.getString("query")));
return queryResult;
}); public Map<String, Object> query(String query) {
return (Map<String, Object>) new GraphQL(schema).execute(query).getData();
}@RequestMapping(value = "/igraphql", method = RequestMethod.POST)
public Map<String, Object> igraph(@RequestBody String json) throws Exception {
logger.debug("JSON " + json);
JSONObject query = new JSONObject(json);
if (query.has("query") && query.getString("query").indexOf("IntrospectionQuery") != -1) {
String introSpection = query.getString("query");
Map<String, Object> result = new HashMap<>();
result.put("data", query(introSpection)); // you have to wrap it into a data json key!
return result;
}
logger.debug("Introspect " + query.getString("query").indexOf("IntrospectionQuery"));
Map<String, Object> queryResult = new HashMap<>(query(query.getString("query")));
return queryResult;
}