== RxJava 3 API

=== Setting up with an Rxified router

To handle GraphQL requests on a Rxified `link:../../apidocs/io/vertx/rxjava3/ext/web/Route.html[Route]`, make sure to import the `link:../../apidocs/io/vertx/rxjava3/ext/web/handler/graphql/GraphQLHandler.html[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_3_api[Web Client]), you will have to adapt the `Single` and `Maybe` objects.

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

[TIP]
====
Instead of converting `Single` or `Maybe` to `CompletionStage` manually in every data fetcher implementation, configure GraphQL-Java with the `link:../../apidocs/io/vertx/rxjava3/ext/web/handler/graphql/instrumentation/SingleAdapter.html[SingleAdapter]` and `link:../../apidocs/io/vertx/rxjava3/ext/web/handler/graphql/instrumentation/MaybeAdapter.html[MaybeAdapter]` https://www.graphql-java.com/documentation/instrumentation/[instrumentations].

First, declare the instrumentations while configuring GraphQL-Java.

[source,java]
----
graphQLBuilder.instrumentation(new ChainedInstrumentation(SingleAdapter.create(), MaybeAdapter.create()));
----

Then you can return `Single` or `Maybe` directly.

[source,java]
----
DataFetcher<Single<List<Link>>> dataFetcher = environment -> {
  Single<List<Link>> single = retrieveLinksFromBackend(environment);
  return single;
};
----
====