title: Prettify GraphQL query string in Java
body: <p>I have a Java program which, among other things, reads raw GraphQL queries from XML files and sends them to a given endpoint via HTTP. The problem is that server accepts only proper formatted GraphQL queries, which means no extra spaces, newlines etc. are allowed. So basically I have to write them in a single line, because any newline symbol will break whole query by adding lots of spaces to match XML hierarchy (element containing query is not root element).
  <p>
  As you can tell, single-lined queries, especially long ones are not human-friendly and they're hard to read. There are a lot of code formatters/prettifyers here and there, online, inside IDEA, Postman, Insomnia etc, all of them can do it in a single button click. </p>
  
  <p>Working XML file (one-lined query):</p>
  
  <pre><code>&lt;request&gt;
      &lt;url&gt;http://localhost:8080/graphql&lt;/url&gt;
      &lt;type&gt;GRAPHQL&lt;/type&gt;
      &lt;body&gt;mutation { login(input: {username: \"user\", password: \"12345\"}) {status}}&lt;/body&gt;
  &lt;/request&gt;
  </code></pre>
  
  <p>Desired XML file (multi-line query):</p>
  
  <pre><code>&lt;request&gt;
      &lt;url&gt;http://localhost:8080/graphql&lt;/url&gt;
      &lt;type&gt;GRAPHQL&lt;/type&gt;
      &lt;body&gt;
          mutation {
            login(input: {username: "user", password: "12345"}) {
              status
            }
          }
      &lt;/body&gt;
  &lt;/request&gt;
  </code></pre>
  
  <p>How can I deal with that scenario? Before sending, I should perform formatting on the 'body' string. Is there any 'prettification' library, or should I write custom symbols 'remover'?</p>