RxJava support
If you're using Apollo Kotlin in a Java project or Kotlin project that uses RxJava, you can use Apollo's RxJava extensions.
To do so, add the apollo-rx2-support-java
/ apollo-rx3-support-java
(Java) or apollo-rx2-support
/ apollo-rx3-support
(Kotlin) dependency to your project:
build.gradle[.kts]
dependencies {// ...// For RxJava 2implementation("com.apollographql.apollo3:apollo-rx2-support-java:4.0.0-alpha.3")// For RxJava 3implementation("com.apollographql.apollo3:apollo-rx3-support-java:4.0.0-alpha.3")}
build.gradle[.kts]
dependencies {// ...// For RxJava 2implementation("com.apollographql.apollo3:apollo-rx2-support:4.0.0-alpha.3")// For RxJava 3implementation("com.apollographql.apollo3:apollo-rx3-support:4.0.0-alpha.3")}
Executing operations
In Java, Use the Rx2Apollo
or Rx3Apollo
classes to execute GraphQL operations and get RxJava observables.
In Kotlin, use the rxSingle()
/ rxFlowable()
extensions.
import com.apollographql.apollo3.rx3.java.Rx3Apollo;// (...)// QueryApolloCall<MyQuery.Data> queryCall = client.query(new MyQuery());Single<ApolloResponse<MyQuery.Data>> queryResponse = Rx3Apollo.single(queryCall);queryResponse.subscribe( /* ... */ );// MutationApolloCall<MyMutation.Data> mutationCall = client.mutation(new MyMutation("my-parameter"));Single<ApolloResponse<MyMutation.Data>> mutationResponse = Rx3Apollo.single(mutationCall);mutationResponse.subscribe( /* ... */ );// SubscriptionApolloCall<MySubscription.Data> subscriptionCall = client.subscription(new MySubscription());Flowable<ApolloResponse<MySubscription.Data>> subscriptionResponse = Rx3Apollo.flowable(subscriptionCall);subscriptionResponse.subscribe( /* ... */ );
// Queryclient.query(MyQuery()).rxSingle().subscribe(/* ... */)// Mutationclient.mutation(MyMutation("my-parameter")).rxSingle().subscribe(/* ... */)// Subscriptionclient.subscription(MySubscription()).rxFlowable().subscribe(/* ... */)