title: Consuming GraphQL API in Spring Boot controller
body: <p>I need to consume graphQL API provided by third party inside my Spring Boot controller, I tried as mentioned <a href="https://stackoverflow.com/questions/42024158/how-to-access-github-graphql-api-using-java">here</a> but getting 400 error.
  Below is the code:</p>
  
  <pre><code>@SuppressWarnings("unchecked")
  @RequestMapping(value = "/graphQLTest")
  public ResponseEntity&lt;?&gt; testGraphQL() throws JsonProcessingException {
  
      CloseableHttpClient client= null;
      CloseableHttpResponse response= null;
  
      client= HttpClients.createDefault();
      HttpPost httpPost= new HttpPost("http://172.30.66.149:3000/graphql");
  
      httpPost.addHeader("Accept","application/json");
  
      try {
          StringEntity entity= new StringEntity("{\"query\":\"{hello}\"}");
  
          httpPost.setEntity(entity);
          response= client.execute(httpPost);
          System.out.println("response: "+response);
      }
  
      catch(UnsupportedEncodingException e){
          e.printStackTrace();
      }
      catch(ClientProtocolException e){
          e.printStackTrace();
      }
      catch(IOException e){
          e.printStackTrace();
      }
  
      return null;
  }
  </code></pre>
  
  <p>When I tried to call same URL in Postman I get the response, below is the screenshot: </p>
  
  <p><a href="https://i.stack.imgur.com/5YMJq.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/5YMJq.png" alt="enter image description here"></a></p>
  
  <p>But when I try it in my controller, I get below error, Can anyone help me out how can I consume someone's GraphQL API .</p>
  
  <p><code>Error: HttpResponseProxy{HTTP/1.1 400 Bad Request [X-Powered-By: Express, Content-Type: application/json; charset=utf-8, Content-Length: 53, ETag: W/"35-1vperDe+r7EpHry/i+J3wg", Date: Tue, 24 Apr 2018 12:32:52 GMT, Connection: keep-alive] ResponseEntityProxy{[Content-Type: application/json; charset=utf-8,Content-Length: 53,Chunked: false]}}</code></p>