Created
          October 13, 2016 02:37 
        
      - 
      
- 
        Save nwillc/1b168093b8f28bd383374bc37b3b11ca to your computer and use it in GitHub Desktop. 
    Attaching graphql-java to sparkjava
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | 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