/
Launch Apollo Studio

Mutiny


Apollo Android includes support for Mutiny.

Apollo types can be converted to Mutiny Uni types using wrapper functions MutinyApollo.from(...) in Java or using extension functions in Kotlin.

Conversion is done according to the following table:

Apollo typeMutiny type
ApolloCall<T>Uni<Response<T>>
ApolloSubscriptionCall<T>Multi<Response<T>>
ApolloQueryWatcher<T>Uni<Response<T>>
ApolloStoreOperation<T>Uni<T>
ApolloPrefetchUni<Void>

Prerequisites

See Mutiny documentation

Including in your project

Add the following dependency:

// Mutiny support
implementation 'com.apollographql.apollo:apollo-mutiny-support:x.y.z'

Usage examples

Converting ApolloCall to an Uni

Java:

// Create a query object
EpisodeHeroName query = EpisodeHeroName.builder().episode(Episode.EMPIRE).build();

// Create an ApolloCall object
ApolloCall<EpisodeHeroName.Data> apolloCall = apolloClient.query(query);

// Mutiny Uni
Uni<Response<EpisodeHeroName.Data>> uni = MutinyApollo.from(apolloCall);

Kotlin:

// Create a query object
val query = EpisodeHeroNameQuery(episode = Episode.EMPIRE.toInput())

// Directly create Uni with Kotlin extension
val uni = apolloClient.mutinyQuery(query)

Converting ApolloPrefetch to a Uni<Void>

Java:

//Create a query object
EpisodeHeroName query = EpisodeHeroName.builder().episode(Episode.EMPIRE).build();

//Create an ApolloPrefetch object
ApolloPrefetch<EpisodeHeroName.Data> apolloPrefetch = apolloClient.prefetch(query);

//Mutiny Uni<Void>
Uni<Void> uni = MutinyApollo.from(apolloPrefetch);

Kotlin:

// Create a query object
val query = EpisodeHeroNameQuery(episode = Episode.EMPIRE.toInput())

// Create Uni for prefetch with Kotlin extension
val uni = apolloClient.mutinyPrefetch(query)

Also, don't forget to cancel of your Observer/Subscriber when you are finished:

Cancellable cancellable = ReactorApollo.from(query).subscribe().with(item -> log("👍 " + item))

//Cancel of your Observer when you are done with your work
cancellable.cancel();
Edit on GitHub