Class AsyncDataFetcher<T>

java.lang.Object
graphql.schema.AsyncDataFetcher<T>
All Implemented Interfaces:
DataFetcher<CompletableFuture<T>>

@PublicApi public class AsyncDataFetcher<T> extends Object implements DataFetcher<CompletableFuture<T>>
A modifier type that indicates the underlying data fetcher is run asynchronously
  • Constructor Details

    • AsyncDataFetcher

      public AsyncDataFetcher(DataFetcher<T> wrappedDataFetcher)
    • AsyncDataFetcher

      public AsyncDataFetcher(DataFetcher<T> wrappedDataFetcher, Executor executor)
  • Method Details

    • async

      public static <T> AsyncDataFetcher<T> async(DataFetcher<T> wrappedDataFetcher)
      A factory method for creating asynchronous data fetchers so that when used with static imports allows more readable code such as:

      .dataFetcher(async(fooDataFetcher))

      By default this will run in the ForkJoinPool.commonPool(). You can set your own Executor with async(DataFetcher, Executor)

      Type Parameters:
      T - the type of data
      Parameters:
      wrappedDataFetcher - the data fetcher to run asynchronously
      Returns:
      a DataFetcher that will run the wrappedDataFetcher asynchronously
    • async

      public static <T> AsyncDataFetcher<T> async(DataFetcher<T> wrappedDataFetcher, Executor executor)
      A factory method for creating asynchronous data fetchers and setting the Executor they run in so that when used with static imports allows more readable code such as:

      .dataFetcher(async(fooDataFetcher, fooExecutor))

      Type Parameters:
      T - the type of data
      Parameters:
      wrappedDataFetcher - the data fetcher to run asynchronously
      executor - the executor to run the asynchronous data fetcher in
      Returns:
      a DataFetcher that will run the wrappedDataFetcher asynchronously in the given Executor
    • getWrappedDataFetcher

      public DataFetcher<T> getWrappedDataFetcher()
    • getExecutor

      public Executor getExecutor()
    • get

      public CompletableFuture<T> get(DataFetchingEnvironment environment)
      Description copied from interface: DataFetcher
      This is called by the graphql engine to fetch the value. The DataFetchingEnvironment is a composite context object that tells you all you need to know about how to fetch a data value in graphql type terms.
      Specified by:
      get in interface DataFetcher<T>
      Parameters:
      environment - this is the data fetching environment which contains all the context you need to fetch a value
      Returns:
      a value of type T. May be wrapped in a DataFetcherResult