title: How to compare GraphQL query tree in java
body: <p>My spring-boot application is generating GraphQL queries, however I want to compare that query in my test.</p>
  <p>So basically I have two strings where the first one is containing the actual value and the latter one the expected value.
  I want to parse that in a class or tree node so I can compare them if both of them are equal.
  So even if the order of the fields are different, I need to know if it's the same query.</p>
  <p>So for example we have these two queries:
  Actual:</p>
  <pre><code>query Query {
   car {
    brand
    color
    year
   }
   person {
    name
    age
   }
  }
  </code></pre>
  <p>Expected</p>
  <pre><code>query Query {
   person {
    age
    name
   }
   car {
    brand
    color
    year
   }
  }
  </code></pre>
  <p>I expect that these queries both are semantically the same.</p>
  <p>I tried</p>
  <pre class="lang-java prettyprint-override"><code>Parser parser = new Parser();
  Document expectedDocument = parser.parseDocument(expectedValue);
  Document actualDocument = parser.parseDocument(actualValue);
  
  if (expectedDocument.isEqualTo(actualDocument)) {
      return MatchResult.exactMatch();
  }
  </code></pre>
  <p>But found out that it does nothing since the <code>isEqualTo</code> is doing this:</p>
  <pre class="lang-java prettyprint-override"><code>public boolean isEqualTo(Node o) {
      if (this == o) {
          return true;
      } else {
          return o != null &amp;&amp; this.getClass() == o.getClass();
      }
  }
  </code></pre>
  <p>I know with JSON I can use Jackson for this purpose and compare treenodes, or parsing it into a Java object and have my own <code>equals()</code> implementation, but I don't know how to do that for GraphQL Java.</p>
  <p>How can I parse my GraphQL query string into an object so that I can compare it?</p>