Join us from October 8-10 in New York City to learn the latest tips, trends, and news about GraphQL federation and API platform engineering.Join us for GraphQL Summit 2024 in NYC
Docs
Start for Free

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.4")
// For RxJava 3
implementation("com.apollographql.apollo3:apollo-rx3-support:3.8.4")
}

Executing operations

Use the rxSingle / rxFlowable extensions 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
Rate articleRateEdit on GitHubEditForumsDiscord

© 2024 Apollo Graph Inc.

Privacy Policy

Company