== RxJava 2 API

=== Setting up with an Rxified router

To handle GraphQL requests on a Rxified {@link io.vertx.reactivex.ext.web.Route}, make sure to import the {@link io.vertx.reactivex.ext.web.handler.graphql.GraphQLHandler} class.

=== Working with Vert.x Rxified APIs

GraphQL-Java expects `CompletionStage` for asynchronous results in data fetchers and batch loaders.

Therefore, if you work with the Vert.x Rxified APIs (e.g. the https://vertx.io/docs/vertx-web-client/java/#_rxjava_2_api[Web Client] or the https://vertx.io/docs/vertx-cassandra-client/java/#_rxjava_2_api[Cassandra Client]), you will have to adapt the `Single` and `Maybe` objects.

The `RxJava2Jdk8Interop` library provides the tooling to do just that.
Add the following to the _dependencies_ section of your Maven build file:

[source,xml,subs="+attributes"]
----
<dependency>
  <groupId>com.github.akarnokd</groupId>
  <artifactId>rxjava2-jdk8-interop</artifactId>
  <version>0.3.5</version>
</dependency>
----

Or if you use Gradle:

[source,groovy,subs="+attributes"]
----
compile 'com.github.akarnokd:rxjava2-jdk8-interop:0.3.5'
----

Then you can create a data fetcher from a `Single` result:

[source,java]
----
Single<String> data = loadDataFromBackend();
DataFetcher<CompletionStage<String>> fetcher = environment -> {
  return data.to(SingleInterop.get());
};
----

For `Maybe` results, use `MaybeInterop`.
