PluginsJavajava-apollo-android

Java Apollo Android

Package nameWeekly DownloadsVersionLicenseUpdated
@graphql-codegen/java-apollo-androidDownloadsVersionLicenseApr 19th, 2026

Installation

npm i -D @graphql-codegen/java-apollo-android

This plugin and presets creates generated mappers and parsers for a complete type-safe GraphQL requests, for developers that uses Apollo Android runtime.

Config API Reference

package

type: string

Customize the Java package name for the generated operations. The default package name will be generated according to the output file path.

Usage Examples

generates:
  ./app/src/main/java/:
    preset: java-apollo-android
    config:
      package: 'com.my.package.generated.graphql'
    plugins:
      - java-apollo-android

typePackage

type: string

Customize the Java package name for the types generated based on input types.

Usage Examples

generates:
  ./app/src/main/java/:
    preset: java-apollo-android
    config:
      typePackage: 'com.my.package.generated.graphql'
    plugins:
      - java-apollo-android

fragmentPackage

type: string

Customize the Java package name for the fragments generated classes.

Usage Examples

generates:
  ./app/src/main/java/:
    preset: java-apollo-android
    config:
      fragmentPackage: 'com.my.package.generated.graphql'
    plugins:
      - java-apollo-android

fileType

type: FileType

Prepare your env

To get started with these plugins and preset, make sure you have the following installed:

  • Node.js (10 or later)
  • NPM or Yarn

Run the following in your Android project:

npm init --yes
npm install graphql
npm install -D @graphql-codegen/cli @graphql-codegen/java-apollo-android

Then, create codegen.yml with the following configuration:

schema: POINT_TO_YOUR_SCHEMA
documents: POINT_TO_YOUR_GRAPHQL_OPERATIONS
generates:
  ./app/src/main/java/:
    preset: java-apollo-android
    config:
      package: 'com.my.app.generated.graphql'
      fragmentPackage: 'com.my.app.generated.graphql'
      typePackage: 'type'
    plugins:
      - java-apollo-android
💡
Also, make sure to add node_modules to your .gitignore file.

To integrate with your Gradle build, you can add the following to your app Gradle file:

preBuild.doFirst {
  def proc = "yarn graphql-codegen".execute()
  proc.waitForProcessOutput(System.out, System.err)
}

build.dependsOn preBuild

This will make sure to run and generate output before each time you build your project.

Usage

You can find a repository with a working example using AppSync.