Skip to content

v2.5.8

Compare
Choose a tag to compare
@martinbonnin martinbonnin released this 02 Jun 11:11
· 2411 commits to main since this release

Version 2.5.8 adds support for Query Batching thanks to the awesome work of @joaquim-verges (#3117) 🙌 as well as reactor bindings made with 💙 by @aoudiamoncef (#3138). Thanks a lot for making Apollo Android better️!

Query Batching

Query batching collects multiple GraphQL queries happening in a short timeframe and sends them in a single HTTP call to a compatible server. This minimizes the number of HTTP calls, for an exemple when a new screen is displayed and multiple queries are sent at the same time.

To enable batching in your ApolloClient:

val apolloClient = ApolloClient.builder()
        .serverUrl("https://")
        .batchingConfiguration(
            BatchConfig(
                // enable batching
                batchingEnabled = true,
                // check queries every 20ms
                batchIntervalMs = 20,
                // or send as soon as there are 10 queries queued
                maxBatchSize = 10  
            )
        )
        .build()
apolloClient.startBatchPoller()

Execute your queries:

val response = apolloClient.query(MyQuery())
    .toBuilder()
    .canBeBatched(true)
    .build()
    .await()

Stop batching:

apolloClient.stopBatchPoller()

Note: Enabling query batching reduces the number of HTTP calls but increases latency. Since the Batcher is run from a timer, an otherwise fast query will have to wait for both the timer to happen, and the backend to process all the events in the batch.

Reactor bindings

Project reactor is a reactive streams implementation for building non-blocking applications on the JVM. It's often used with Spring Boot for an example.

To add to your project:

// Reactor support
implementation("com.apollographql.apollo:apollo-reactor-support:x.y.z")

The usage is very similar to the RxJava2/RxJava3 bindings:

// Create Mono from a query
val mono = apolloClient.reactorQuery(query)

// Create Flux from a subscription
val flux = apolloClient.reactorSubscribe(subscription)

For more information, refer to the documentation.

Full Changelog

✨ New

  • Implement Query Batching for apollo-runtime (#3117)
  • Add Reactor support (#3138)

👷‍ Fixes

  • [Gradle Plugin] pass 'operationName' in the introspection query (#3126)