// 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;
//             };
//       }
//     };
//   }
// }


import com.google.api.graphql.execution.GuavaListenableFutureSupport;
import com.google.api.graphql.rejoiner.Schema;
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 graphql.ExecutionInput;
import graphql.ExecutionResult;
import graphql.GraphQL;
import graphql.execution.instrumentation.ChainedInstrumentation;
import graphql.execution.instrumentation.Instrumentation;
import graphql.execution.instrumentation.dataloader.DataLoaderDispatcherInstrumentation;
import graphql.execution.instrumentation.tracing.TracingInstrumentation;
import graphql.schema.GraphQLSchema;
import org.dataloader.DataLoaderRegistry;
import javax.inject.Inject;
import javax.inject.Provider;
import javax.inject.Singleton;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.logging.Logger;
// Copyright 2017 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package com.google.api.graphql.examples.library.graphqlserver;



@Singleton
final class GraphQlServlet extends HttpServlet {

  private static final Gson GSON = new GsonBuilder().serializeNulls().create();
  private static final TypeToken<Map<String, Object>> MAP_TYPE_TOKEN =
      new TypeToken<Map<String, Object>>() {};

  private static final Logger logger = Logger.getLogger(GraphQlServlet.class.getName());
  @Inject @Schema GraphQLSchema schema;
  @Inject Provider<DataLoaderRegistry> registryProvider;

  @Override
  protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {

    DataLoaderRegistry dataLoaderRegistry = registryProvider.get();
    Instrumentation instrumentation =
        new ChainedInstrumentation(
            Arrays.asList(
// 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: examples-gradle/src/main/java/com/google/api/graphql/examples/library/graphqlserver/GraphQlServlet.java
import com.google.api.graphql.execution.GuavaListenableFutureSupport;
import com.google.api.graphql.rejoiner.Schema;
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 graphql.ExecutionInput;
import graphql.ExecutionResult;
import graphql.GraphQL;
import graphql.execution.instrumentation.ChainedInstrumentation;
import graphql.execution.instrumentation.Instrumentation;
import graphql.execution.instrumentation.dataloader.DataLoaderDispatcherInstrumentation;
import graphql.execution.instrumentation.tracing.TracingInstrumentation;
import graphql.schema.GraphQLSchema;
import org.dataloader.DataLoaderRegistry;
import javax.inject.Inject;
import javax.inject.Provider;
import javax.inject.Singleton;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.logging.Logger;

// Copyright 2017 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package com.google.api.graphql.examples.library.graphqlserver;



@Singleton
final class GraphQlServlet extends HttpServlet {

  private static final Gson GSON = new GsonBuilder().serializeNulls().create();
  private static final TypeToken<Map<String, Object>> MAP_TYPE_TOKEN =
      new TypeToken<Map<String, Object>>() {};

  private static final Logger logger = Logger.getLogger(GraphQlServlet.class.getName());
  @Inject @Schema GraphQLSchema schema;
  @Inject Provider<DataLoaderRegistry> registryProvider;

  @Override
  protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {

    DataLoaderRegistry dataLoaderRegistry = registryProvider.get();
    Instrumentation instrumentation =
        new ChainedInstrumentation(
            Arrays.asList(
                GuavaListenableFutureSupport.listenableFutureInstrumentation(),