public static JsonNode buildResponseJsonSchema(String schemaText, String query) throws IOException {
      TypeDefinitionRegistry registry = new SchemaParser().parse(schemaText);
      GraphQLSchema schema = new SchemaGenerator().makeExecutableSchema(registry, RuntimeWiring.MOCKED_WIRING);

      Document graphqlRequest = new Parser().parseDocument(query);
      QueryTraverser queryTraversal = QueryTraverser.newQueryTraverser().schema(schema).document(graphqlRequest)
            .variables(new HashMap<>()).build();

      ObjectNode jsonSchema = initResponseJsonSchema();
      QueryVisitor visitor = new JsonSchemaBuilderQueryVisitor(
            (ObjectNode) jsonSchema.get("properties").get(GRAPHQL_RESPONSE_DATA));

      queryTraversal.visitPreOrder(visitor);
      return jsonSchema;
   }
@Test
   void testBuildResponseJsonSchema() {
      String schemaText;
      String queryText = "{\n" + "  hero {\n" + "    name\n" + "    email\n" + "    family\n" + "    affiliate\n"
            + "    movies {\n" + "      title\n" + "    }\n" + "  }\n" + "}";

      JsonNode responseSchema = null;
      try {
         // Load schema from file.
         schemaText = FileUtils
               .readFileToString(new File("target/test-classes/io/github/microcks/util/graphql/basic-heroes.graphql"));
         // Build JsonSchema for response.
         responseSchema = GraphQLSchemaValidator.buildResponseJsonSchema(schemaText, queryText);
      } catch (Exception e) {
         fail("Exception should not be thrown");
      }

      assertFalse(
            responseSchema.path("properties").path("data").path("properties").path("hero") instanceof MissingNode);

      ObjectNode heroNode = (ObjectNode) responseSchema.path("properties").path("data").path("properties").path("hero");
      assertEquals("object", heroNode.get("type").asText());
      assertEquals(JsonNodeType.OBJECT, heroNode.get("properties").getNodeType());
      assertEquals(JsonNodeType.ARRAY, heroNode.get("required").getNodeType());
      assertEquals(JsonNodeType.BOOLEAN, heroNode.get("additionalProperties").getNodeType());

      ArrayNode requiredHero = (ArrayNode) heroNode.get("required");
      assertEquals(5, requiredHero.size());
      Iterator<JsonNode> requiredHeroElements = requiredHero.elements();
      while (requiredHeroElements.hasNext()) {
         String requiredHeroField = requiredHeroElements.next().asText();
         assertTrue("name".equals(requiredHeroField) || "email".equals(requiredHeroField)
               || "family".equals(requiredHeroField) || "affiliate".equals(requiredHeroField)
               || "movies".equals(requiredHeroField));
      }

      ObjectNode moviesNode = (ObjectNode) heroNode.path("properties").path("movies");
      assertEquals("array", moviesNode.get("type").asText());
      assertEquals(JsonNodeType.OBJECT, moviesNode.get("items").getNodeType());

      ObjectNode movieItemsNode = (ObjectNode) moviesNode.get("items");
      assertEquals("object", movieItemsNode.get("type").asText());
      assertEquals(JsonNodeType.OBJECT, movieItemsNode.get("properties").getNodeType());
      assertEquals(JsonNodeType.ARRAY, movieItemsNode.get("required").getNodeType());
      assertEquals(JsonNodeType.BOOLEAN, movieItemsNode.get("additionalProperties").getNodeType());

      ArrayNode requiredMovie = (ArrayNode) movieItemsNode.get("required");
      assertEquals(1, requiredMovie.size());
   }