RxJava support
If you're using Apollo Kotlin in a Java project or a Kotlin project that uses RxJava, you can use Apollo's RxJava extensions.
To do so, add the apollo-rx2-support
or apollo-rx3-support
dependency to your project:
Kotlin
build.gradle[.kts]
1dependencies {
2 // ...
3
4 // For RxJava 2
5 implementation("com.apollographql.apollo3:apollo-rx2-support:3.8.5")
6
7 // For RxJava 3
8 implementation("com.apollographql.apollo3:apollo-rx3-support:3.8.5")
9}
Executing operations
Use the rxSingle
/ rxFlowable
extensions to execute GraphQL operations and get RxJava observables:
Java
Kotlin
1import com.apollographql.apollo3.rx2.Rx2Apollo;
2
3// (...)
4
5// Query
6ApolloCall<MyQuery.Data> queryCall = client.query(new MyQuery());
7Single<ApolloResponse<MyQuery.Data>> queryResponse = Rx2Apollo.single(queryCall);
8queryResponse.subscribe( /* ... */ );
9
10// Mutation
11ApolloCall<MyMutation.Data> mutationCall = client.mutation(new MyMutation("my-parameter"));
12Single<ApolloResponse<MyMutation.Data>> mutationResponse = Rx2Apollo.single(mutationCall);
13mutationResponse.subscribe( /* ... */ );
14
15// Subscription
16ApolloCall<MySubscription.Data> subscriptionCall = client.subscription(new MySubscription());
17Flowable<ApolloResponse<MySubscription.Data>> subscriptionResponse = Rx2Apollo.flowable(subscriptionCall);
18subscriptionResponse.subscribe( /* ... */ );
1// Query
2client.query(MyQuery()).rxSingle().subscribe(/* ... */)
3
4// Mutation
5client.mutation(MyMutation("my-parameter")).rxSingle().subscribe(/* ... */)
6
7// Subscription
8client.subscription(MySubscription()).rxFlowable().subscribe(/* ... */)