Query Batching in Android Client

Team,
i am using the Apollo android Client and wanted to explore the Batching Functionality, i explored the API but wanted to know the logical correctness of the code for Batched Execution of Queries.

Should we execute the queries one after another within the startBatchPoller() and stopBatchPoller() method?

BatchConfig batchConfig = new BatchConfig(true,10,15);
ApolloClient apolloClient = ApolloClient.builder()
                .serverUrl(graphQLServerURL)
                .okHttpClient(new OkHttpClient.Builder().addInterceptor(new AuthorizationInterceptor()).build())
                .batchingConfiguration(batchConfig)
                .build();

        apolloClient.startBatchPoller();
        apolloclient.enqueue(query1);
        apolloclient.enqueue(query2);
        apolloclient.enqueue(query3);
        apolloClient.stopBatchPoller();

or if there are any other ways please do let me know, how to run Queries in Batch Operation?

Thanks in Advance!!
Appreciate your help.

Hi! :wave:

Yes that’s how you would use it, except you will need to explicitly opt-in for batching on individual queries, with .canBeBatched(true).

Also the call stopBatchPoller can be done later, when disposing of your apolloClient.

You can have a look at a unit test showcasing this here (in Kotlin but equivalent Java code should be fairly equivalent).

Hi @Benoit_Lubek , is Batching part of Version 3 library? I am using 2.5.11 version of Apollo Libraries.

Yes, batching is also available in v3. Its usage is a bit different, but similar - you can have a look at the doc for it here.