Skip to content
🤖 A strongly-typed, caching GraphQL client for Android and the JVM
Java Kotlin Other
Branch: master
Clone or download

Latest commit


Type Name Latest commit message Commit time
Failed to load latest commit information.
.github fix bad copy/paste (#2237) May 1, 2020
.idea/codeStyles Apollo normalized cache module (#2142) Apr 7, 2020
apollo-android-support Replace legacy Android SQL with SqlDelight (#2158) Apr 13, 2020
apollo-api [Runtime] convert to Kotlin (#2295) May 21, 2020
apollo-compiler [Gradle Plugin] Use relative strings for the rootFolder input propert… May 23, 2020
apollo-coroutines-support Fix eager `asFlow()` completion (#2214) Apr 25, 2020
apollo-gradle-plugin [Gradle Plugin] Use relative strings for the rootFolder input propert… May 23, 2020
apollo-http-cache-api Fix issue with HttpCache causes HttpParseException (#2107) Mar 30, 2020
apollo-http-cache Fix issue with HttpCache causes HttpParseException (#2107) Mar 30, 2020
apollo-idling-resource Add overloaded constructors for SqlNormalizedCacheFactory (#2189) Apr 17, 2020
apollo-integration Make Execution context more Kotlin coroutine context idiomatic (#2258) May 11, 2020
apollo-normalized-cache-api Convert cache-api module to multiplatform (#2211) Apr 30, 2020
apollo-normalized-cache-sqlite Fix issue with sql cache not updated for the same CacheKey (#2245) May 5, 2020
apollo-normalized-cache Convert cache-api module to multiplatform (#2211) Apr 30, 2020
apollo-runtime-kotlin Introduce Http execution context in kotlin runtime module (#2284) May 22, 2020
apollo-runtime Fix wrong error message in CallState (#2290) May 21, 2020
apollo-rx2-support Fix some of the dependency issues (#2168) Apr 14, 2020
composite Kotlin Multiplatform Sample (#2136) Apr 5, 2020
docs Add info about matchingFallbacks (#2300) May 23, 2020
gradle version is now 2.1.1-SNAPSHOT May 21, 2020
samples Introduce Http execution context in kotlin runtime module (#2284) May 22, 2020
scripts enable checkstyle again (#2296) May 21, 2020
.gitignore Migrate tests to Kotlin to keep previously package-private function i… Apr 14, 2020 Export gradle publish credentials to the CI script and add a note to … Apr 30, 2020
LICENSE Change copyright in license to Meteor instead of Apollo Jan 23, 2017 Minor documentation tweaks (#2266) May 16, 2020 update (#2101) Mar 25, 2020
build.gradle.kts revert okhttp to 3.12.11 to continue supporting Android 4.4 (#2269) May 19, 2020
checkstyle.xml bump gradle version to 6.2.2 (#2085) Mar 22, 2020 version is now 2.1.1-SNAPSHOT May 21, 2020
gradlew bump gradle version to 6.2.2 (#2085) Mar 22, 2020
gradlew.bat bump gradle version to 6.2.2 (#2085) Mar 22, 2020
netlify.toml Avoid doc duplication by using on gatsby as well (#2053) Mar 8, 2020
renovate.json Remove nested renovation configuration (#867) Apr 6, 2018
settings.gradle.kts Kotlin runtime initial structure (#2256) May 13, 2020

Apollo GraphQL Client for Android and the JVM

GitHub license Join Spectrum CI GitHub release

Apollo-Android is a GraphQL compliant client that generates Java and Kotlin models from standard GraphQL queries. These models give you a typesafe API to work with GraphQL servers. Apollo will help you keep your GraphQL query statements together, organized, and easy to access. Change a query and recompile your project - Apollo code gen will rebuild your data model. Code generation also allows Apollo to read and unmarshal responses from the network without the need of any reflection.

Apollo-Android is designed primarily with Android in mind but you can use it in any Java/Kotlin app. The android-only parts are in apollo-android-support and are only needed to use SQLite as a cache or the android main thread for callbacks.

Apollo-android features:

  • Automatic generation of typesafe models.
  • Support for Java and Kotlin code generation.
  • Queries, Mutations and Subscriptions.
  • Reflection-free parsing of responses.
  • HTTP cache.
  • Normalized cache.
  • File Upload.
  • Custom scalar types.
  • Support for RxJava2 and Coroutines.

Adding Apollo-Android to your Project

The latest Gradle plugin version is Download

To use this plugin, add the dependency to your project's root build.gradle file:

buildscript {
  repositories {
  dependencies {

Then add the dependencies to your app's build.gradle and apply file and apply the com.apollographql.apollo plugin:

apply plugin: 'com.apollographql.apollo'

repositories {

dependencies {
  // If not already on your classpath, you might need the jetbrains annotations

Generating models from your queries

  1. Create a directory for your GraphQL files like you would do for Java/Kotlin: src/main/graphql/com/example/. Apollo-Android will generate models in the com.apollographql.apollo.sample package.
  2. Add your schema.json to the directory at src/main/graphql/com/example/schema.json. If you don't have a schema.json file yet, read the section about downloading a schema file.
  3. Put your GraphQL queries in a .graphql files. For an example: src/main/graphql/com/example/feed.graphql:
query FeedQuery($type: FeedType!, $limit: Int!) {
  feed(type: $type, limit: $limit) {
    comments {
    repository {
    postedBy {

fragment RepositoryFragment on Repository {
  owner {

fragment FeedCommentFragment on Comment {
  postedBy {
  1. Decide if you want to generate Kotlin or Java models:
// build.gradle or build.gradle.kts
apollo {
  generateKotlinModels.set(true) // or false for Java models
  1. Execute ./gradlew generateApolloSources to generate the models from your queries. This will create a generated FeedQuery Java or Kotlin source file for your query.

Consuming Code

Apollo includes an ApolloClient to interact with your server and cache.

To make a query using the generated models:

).enqueue(new ApolloCall.Callback<FeedQuery.Data>() {

  @Override public void onResponse(@NotNull Response<FeedQuery.Data> dataResponse) {

    final StringBuffer buffer = new StringBuffer();
    for (FeedQuery.Data.Feed feed : {
      buffer.append("name:" + feed.repository().fragments().repositoryFragment().name());
      buffer.append(" postedBy: " + feed.postedBy().login());

    // onResponse returns on a background thread. If you want to make UI updates make sure they are done on the Main Thread.
    MainActivity.this.runOnUiThread(new Runnable() {
      @Override public void run() {
        TextView txtResponse = (TextView) findViewById(;

  @Override public void onFailure(@NotNull Throwable t) {
    Log.e(TAG, t.getMessage(), t);

Custom Scalar Types

Apollo supports Custom Scalar Types like Date.

You first need to define the mapping in your build.gradle file. This maps from the GraphQL type to the Java/Kotlin class to use in code.

apollo {
  customTypeMapping = [
    "Date" : "java.util.Date"

Next register your custom adapter & add it to your Apollo Client Builder:

 dateCustomTypeAdapter = new CustomTypeAdapter<Date>() {
      @Override public Date decode(CustomTypeValue value) {
        try {
          return DATE_FORMAT.parse(value.value.toString());
        } catch (ParseException e) {
          throw new RuntimeException(e);

      @Override public CustomTypeValue encode(Date value) {
        return new CustomTypeValue.GraphQLString(DATE_FORMAT.format(value));

  .addCustomTypeAdapter(CustomType.DATE, dateCustomTypeAdapter)

If you have compiler warnings as errors (options.compilerArgs << "-Xlint" << "-Werror") turned on, your custom type will not compile. You can add a switch suppressRawTypesWarning to the apollo plugin configuration which will annotate your generated class with the proper suppression (@SuppressWarnings("rawtypes"):

apollo {
    customTypeMapping = [
      "URL" : "java.lang.String"
    suppressRawTypesWarning = "true"

Downloading a schema.json file

You can get a schema.json file by running an introspection query on your endpoint. The Apollo Gradle plugin exposes a downloadApolloSchema task to help with this. You can download a schema by specifying your endpoint and the location where you want the schema to be downloaded:

./gradlew :module:downloadApolloSchema -Pcom.apollographql.apollo.endpoint=https://your.graphql.endpoint -Pcom.apollographql.apollo.schema=src/main/graphql/com/example/schema.json

If your endpoint requires authentication, you can pass query parameters and/or custom HTTP headers:

./gradlew :module:downloadApolloSchema -Pcom.apollographql.apollo.endpoint=https://your.graphql.endpoint -Pcom.apollographql.apollo.schema=src/main/graphql/com/example/schema.json  "-Pcom.apollographql.apollo.headers=Authorization=Bearer YOUR_TOKEN" "-Pcom.apollographql.apollo.query_params=key1=value1&key2=value2"

The com.apollographql.apollo.headers and com.apollographql.apollo.query_params properties both take a query string where key and values should be URL encoded.

The default timeout for download operation is 1 minute. If you have a large schema.json, you may want to increase the timeout. Do that by adding the following into

org.gradle.jvmargs=-DokHttp.connectTimeout=60 -DokHttp.readTimeout=60

Intellij Plugin

The JS Graphql Intellij Plugin provides auto-completion, error highlighting, and go-to-definition functionality for your graphql files. You can create a .graphqlconfig file in order to use GraphQL scratch files to work with your schema outside product code, e.g. by writing temporary queries to test resolvers.


Our release history has the release history.

Releases are hosted on jcenter.

Latest development changes are available in Sonatype's snapshots repository:

  repositories {
    maven { url '' }

Advanced topics

Advanced topics are available in the official docs:


Read about the latest changes to the library


If you'd like to contribute, please refer to the Apollo Contributor Guide.

Note: Running samples require importing composite folder instead of root.


The MIT License (MIT)

Copyright (c) 2019 Meteor Development Group, Inc.
You can’t perform that action at this time.