// Path: rejoiner/src/main/java/com/google/api/graphql/execution/GuavaListenableFutureSupport.java
// public final class GuavaListenableFutureSupport {
//   private GuavaListenableFutureSupport() {}
// 
//   /**
//    * Converts a {@link ListenableFuture} to a Java8 {@link java.util.concurrent.CompletableFuture}.
//    *
//    * <p>{@see CompletableFuture} is supported by the provided {@link
//    * graphql.execution.AsyncExecutionStrategy}.
//    *
//    * <p>Note: This should be installed before any other instrumentation.
//    */
//   public static Instrumentation listenableFutureInstrumentation() {
//     return listenableFutureInstrumentation(MoreExecutors.directExecutor());
//   }
// 
//   /**
//    * Converts a {@link ListenableFuture} to a Java8 {@link java.util.concurrent.CompletableFuture}.
//    *
//    * <p>{@see CompletableFuture} is supported by the provided {@link
//    * graphql.execution.AsyncExecutionStrategy}.
//    *
//    * <p>Note: This should be installed before any other instrumentation.
//    */
//   public static Instrumentation listenableFutureInstrumentation(Executor executor) {
//     return new SimpleInstrumentation() {
//       @Override
//       public DataFetcher<?> instrumentDataFetcher(
//           DataFetcher<?> dataFetcher, InstrumentationFieldFetchParameters parameters) {
//         return (DataFetcher<Object>)
//             dataFetchingEnvironment -> {
//               Object data = dataFetcher.get(dataFetchingEnvironment);
//               if (data instanceof ListenableFuture) {
//                 ListenableFuture<Object> listenableFuture = (ListenableFuture<Object>) data;
//                 CompletableFuture<Object> completableFuture = new CompletableFuture<>();
//                 Futures.addCallback(
//                     listenableFuture,
//                     new FutureCallback<Object>() {
//                       @Override
//                       public void onSuccess(Object result) {
//                         completableFuture.complete(result);
//                       }
// 
//                       @Override
//                       public void onFailure(Throwable t) {
//                         completableFuture.completeExceptionally(t);
//                       }
//                     },
//                     executor);
//                 return completableFuture;
//               }
//               return data;
//             };
//       }
//     };
//   }
// }
// 
// Path: rejoiner-guice/src/main/java/com/google/api/graphql/rejoiner/SchemaProviderModule.java
// public final class SchemaProviderModule extends AbstractModule {
// 
//   static class SchemaImpl implements Provider<GraphQLSchema> {
// 
//     private final Provider<Set<SchemaBundle>> schemaBundleProviders;
// 
//     @Inject
//     public SchemaImpl(@Annotations.SchemaBundles Provider<Set<SchemaBundle>> schemaBundles) {
//       this.schemaBundleProviders = schemaBundles;
//     }
// 
//     @Override
//     public GraphQLSchema get() {
//       SchemaBundle schemaBundle = SchemaBundle.combine(schemaBundleProviders.get());
//       return schemaBundle.toSchema();
//     }
//   }
// 
//   @Override
//   protected void configure() {
//     bind(GraphQLSchema.class)
//         .annotatedWith(Schema.class)
//         .toProvider(SchemaImpl.class)
//         .in(Singleton.class);
//   }
// }


import com.google.api.graphql.execution.GuavaListenableFutureSupport;
import com.google.api.graphql.rejoiner.Schema;
import com.google.api.graphql.rejoiner.SchemaProviderModule;
import com.google.common.base.Strings;
import com.google.common.collect.ImmutableMap;
import com.google.common.io.CharStreams;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken;
import com.google.inject.Guice;
import com.google.inject.Key;
import graphql.ExecutionInput;
import graphql.ExecutionResult;
import graphql.GraphQL;
import graphql.execution.instrumentation.ChainedInstrumentation;
import graphql.execution.instrumentation.Instrumentation;
import graphql.execution.instrumentation.tracing.TracingInstrumentation;
import graphql.schema.GraphQLSchema;
import java.io.IOException;
import java.util.*;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.handler.AbstractHandler;
      String query = (String) json.get("query");
      if (query == null) {
        httpServletResponse.setStatus(400);
        return;
      }
      String operationName = (String) json.get("operationName");
      Map<String, Object> variables = getVariables(json.get("variables"));

      ExecutionInput executionInput =
          ExecutionInput.newExecutionInput()
              .query(query)
              .operationName(operationName)
              .variables(variables)
              .context(new Object())
              .build();
      ExecutionResult executionResult = GRAPHQL.execute(executionInput);
      httpServletResponse.setContentType("application/json");
      httpServletResponse.setStatus(HttpServletResponse.SC_OK);
      GSON.toJson(executionResult.toSpecification(), httpServletResponse.getWriter());
    }
  }

  private static Map<String, Object> getVariables(Object variables) {
    Map<String, Object> variablesWithStringKey = new HashMap<>();
    if (variables instanceof Map) {
      ((Map) variables).forEach((k, v) -> variablesWithStringKey.put(String.valueOf(k), v));
    }
    return variablesWithStringKey;
  }

// Path: rejoiner/src/main/java/com/google/api/graphql/execution/GuavaListenableFutureSupport.java
// public final class GuavaListenableFutureSupport {
//   private GuavaListenableFutureSupport() {}
// 
//   /**
//    * Converts a {@link ListenableFuture} to a Java8 {@link java.util.concurrent.CompletableFuture}.
//    *
//    * <p>{@see CompletableFuture} is supported by the provided {@link
//    * graphql.execution.AsyncExecutionStrategy}.
//    *
//    * <p>Note: This should be installed before any other instrumentation.
//    */
//   public static Instrumentation listenableFutureInstrumentation() {
//     return listenableFutureInstrumentation(MoreExecutors.directExecutor());
//   }
// 
//   /**
//    * Converts a {@link ListenableFuture} to a Java8 {@link java.util.concurrent.CompletableFuture}.
//    *
//    * <p>{@see CompletableFuture} is supported by the provided {@link
//    * graphql.execution.AsyncExecutionStrategy}.
//    *
//    * <p>Note: This should be installed before any other instrumentation.
//    */
//   public static Instrumentation listenableFutureInstrumentation(Executor executor) {
//     return new SimpleInstrumentation() {
//       @Override
//       public DataFetcher<?> instrumentDataFetcher(
//           DataFetcher<?> dataFetcher, InstrumentationFieldFetchParameters parameters) {
//         return (DataFetcher<Object>)
//             dataFetchingEnvironment -> {
//               Object data = dataFetcher.get(dataFetchingEnvironment);
//               if (data instanceof ListenableFuture) {
//                 ListenableFuture<Object> listenableFuture = (ListenableFuture<Object>) data;
//                 CompletableFuture<Object> completableFuture = new CompletableFuture<>();
//                 Futures.addCallback(
//                     listenableFuture,
//                     new FutureCallback<Object>() {
//                       @Override
//                       public void onSuccess(Object result) {
//                         completableFuture.complete(result);
//                       }
// 
//                       @Override
//                       public void onFailure(Throwable t) {
//                         completableFuture.completeExceptionally(t);
//                       }
//                     },
//                     executor);
//                 return completableFuture;
//               }
//               return data;
//             };
//       }
//     };
//   }
// }
// 
// Path: rejoiner-guice/src/main/java/com/google/api/graphql/rejoiner/SchemaProviderModule.java
// public final class SchemaProviderModule extends AbstractModule {
// 
//   static class SchemaImpl implements Provider<GraphQLSchema> {
// 
//     private final Provider<Set<SchemaBundle>> schemaBundleProviders;
// 
//     @Inject
//     public SchemaImpl(@Annotations.SchemaBundles Provider<Set<SchemaBundle>> schemaBundles) {
//       this.schemaBundleProviders = schemaBundles;
//     }
// 
//     @Override
//     public GraphQLSchema get() {
//       SchemaBundle schemaBundle = SchemaBundle.combine(schemaBundleProviders.get());
//       return schemaBundle.toSchema();
//     }
//   }
// 
//   @Override
//   protected void configure() {
//     bind(GraphQLSchema.class)
//         .annotatedWith(Schema.class)
//         .toProvider(SchemaImpl.class)
//         .in(Singleton.class);
//   }
// }


// Path: examples-gradle/src/main/java/com/google/api/graphql/examples/helloworld/graphqlserver/GraphQlHandler.java
import com.google.api.graphql.execution.GuavaListenableFutureSupport;
import com.google.api.graphql.rejoiner.Schema;
import com.google.api.graphql.rejoiner.SchemaProviderModule;
import com.google.common.base.Strings;
import com.google.common.collect.ImmutableMap;
import com.google.common.io.CharStreams;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken;
import com.google.inject.Guice;
import com.google.inject.Key;
import graphql.ExecutionInput;
import graphql.ExecutionResult;
import graphql.GraphQL;
import graphql.execution.instrumentation.ChainedInstrumentation;
import graphql.execution.instrumentation.Instrumentation;
import graphql.execution.instrumentation.tracing.TracingInstrumentation;
import graphql.schema.GraphQLSchema;
import java.io.IOException;
import java.util.*;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.handler.AbstractHandler;

      String query = (String) json.get("query");
      if (query == null) {
        httpServletResponse.setStatus(400);
        return;
      }
      String operationName = (String) json.get("operationName");
      Map<String, Object> variables = getVariables(json.get("variables"));

      ExecutionInput executionInput =
          ExecutionInput.newExecutionInput()
              .query(query)
              .operationName(operationName)
              .variables(variables)
              .context(new Object())
              .build();
      ExecutionResult executionResult = GRAPHQL.execute(executionInput);
      httpServletResponse.setContentType("application/json");
      httpServletResponse.setStatus(HttpServletResponse.SC_OK);
      GSON.toJson(executionResult.toSpecification(), httpServletResponse.getWriter());
    }
  }

  private static Map<String, Object> getVariables(Object variables) {
    Map<String, Object> variablesWithStringKey = new HashMap<>();
    if (variables instanceof Map) {
      ((Map) variables).forEach((k, v) -> variablesWithStringKey.put(String.valueOf(k), v));
    }
    return variablesWithStringKey;
  }

  private static Map<String, Object> readJson(HttpServletRequest request) {