Skip to content

Instantly share code, notes, and snippets.

@nwillc
Last active October 13, 2016 02:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nwillc/9f990efda61ee3952e2c0a42ddab0a7f to your computer and use it in GitHub Desktop.
Save nwillc/9f990efda61ee3952e2c0a42ddab0a7f to your computer and use it in GitHub Desktop.
private Map<String, Object> graphql(Request request,
Response response) {
Map<String, Object> payload;
payload = getMapper().readValue(request.body(), Map.class);
Map<String,Object> variables =
(Map<String, Object>) payload.get("variables");
ExecutionResult executionResult =
graphql.execute(payload.get("query").toString(), null, null, variables);
Map<String, Object> result = new LinkedHashMap<>();
if (executionResult.getErrors().size() > 0) {
result.put("errors", executionResult.getErrors());
}
result.put("data", executionResult.getData());
response.type("application/json");
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment