Join us for GraphQL Summit, October 10-12 in San Diego. Use promo code ODYSSEY for $400 off your pass.
Docs
Launch GraphOS Studio
You're viewing documentation for an upcoming version of this software. Switch to the latest stable version.

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 2
implementation("com.apollographql.apollo3:apollo-rx2-support-java:4.0.0-alpha.3")
// For RxJava 3
implementation("com.apollographql.apollo3:apollo-rx3-support-java:4.0.0-alpha.3")
}
build.gradle[.kts]
dependencies {
// ...
// For RxJava 2
implementation("com.apollographql.apollo3:apollo-rx2-support:4.0.0-alpha.3")
// For RxJava 3
implementation("com.apollographql.apollo3:apollo-rx3-support:4.0.0-alpha.3")
}

Executing operations

In Java, Use the Rx2Apollo or Rx3Apollo classes to execute GraphQL s and get RxJava observables.

In Kotlin, use the rxSingle() / rxFlowable() extensions.

import com.apollographql.apollo3.rx3.java.Rx3Apollo;
// (...)
// Query
ApolloCall<MyQuery.Data> queryCall = client.query(new MyQuery());
Single<ApolloResponse<MyQuery.Data>> queryResponse = Rx3Apollo.single(queryCall);
queryResponse.subscribe( /* ... */ );
// Mutation
ApolloCall<MyMutation.Data> mutationCall = client.mutation(new MyMutation("my-parameter"));
Single<ApolloResponse<MyMutation.Data>> mutationResponse = Rx3Apollo.single(mutationCall);
mutationResponse.subscribe( /* ... */ );
// Subscription
ApolloCall<MySubscription.Data> subscriptionCall = client.subscription(new MySubscription());
Flowable<ApolloResponse<MySubscription.Data>> subscriptionResponse = Rx3Apollo.flowable(subscriptionCall);
subscriptionResponse.subscribe( /* ... */ );
// Query
client.query(MyQuery()).rxSingle().subscribe(/* ... */)
// Mutation
client.mutation(MyMutation("my-parameter")).rxSingle().subscribe(/* ... */)
// Subscription
client.subscription(MySubscription()).rxFlowable().subscribe(/* ... */)
Previous
Using with Java
Next
Kotlin native
Edit on GitHubEditForumsDiscord