Docs
Launch GraphOS Studio

RxJava support


If you're using in a Java project or a Kotlin project that uses RxJava, you can use Apollo's RxJava .

To do so, add the apollo-rx2-support or apollo-rx3-support dependency to your project:

build.gradle[.kts]
dependencies {
// ...
// For RxJava 2
implementation("com.apollographql.apollo3:apollo-rx2-support:3.8.2")
// For RxJava 3
implementation("com.apollographql.apollo3:apollo-rx3-support:3.8.2")
}

Executing operations

Use the rxSingle / rxFlowable to execute and get RxJava observables:

import com.apollographql.apollo3.rx2.Rx2Apollo;
// (...)
// Query
ApolloCall<MyQuery.Data> queryCall = client.query(new MyQuery());
Single<ApolloResponse<MyQuery.Data>> queryResponse = Rx2Apollo.single(queryCall);
queryResponse.subscribe( /* ... */ );
// Mutation
ApolloCall<MyMutation.Data> mutationCall = client.mutation(new MyMutation("my-parameter"));
Single<ApolloResponse<MyMutation.Data>> mutationResponse = Rx2Apollo.single(mutationCall);
mutationResponse.subscribe( /* ... */ );
// Subscription
ApolloCall<MySubscription.Data> subscriptionCall = client.subscription(new MySubscription());
Flowable<ApolloResponse<MySubscription.Data>> subscriptionResponse = Rx2Apollo.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

© 2024 Apollo Graph Inc.

Privacy Policy

Company