apollo-kotlin: Apollo doesn't take into account Android build type graphQL overrides

Summary Overriding graphQL files using the AGPs build type aware source directory approach isn’t taken into account by the apollo Gradle plugin.

Version 2.2.3

Description We are aiming at overriding certain graphQL queries for our release build type. The Android approach would usually look like this:

  1. Define the a default (in our case used for stage and debug builds) query in the main source directory, e.g. app/src/main/graphql/your/app/buildid/datasource/cms/Articles.graphql
  2. Override the default query in the release source directory, in this case app/src/release/graphql/your/app/buildid/datasource/cms/Articles.graphql
  3. This should normally result in the app/src/release/…/Articles.graphql being used for release builds, but that doesn’t seem to be the case - instead the app/src/main/…/Articles.graphql is used.

Here is my apollo Gradle plugin configuration - not sure it is relevant to solving this issue:

apollo {
    generateKotlinModels.set(true)
    schemaFile = file("src/main/graphql/schema.json")
    customTypeMapping = [
            "Date" : "java.util.Date"
    ]
}

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 23 (16 by maintainers)

Most upvoted comments

Hi @m-abyzov !

The new way to take Android buildTypes / variants into accounts is with createAllAndroidVariantServices.

For example:

apollo {
    createAllAndroidVariantServices(".", "") {
        packageName.set("com.example.myapp")
    }
}

The documentation is here.

Let us know if that works for you!

Hello @m-abyzov and @timkabot, just a follow-up to say that we’ve added a section on the documentation about createAllAndroidVariantServices here, and also made a change so that testDebug no longer triggers the code generation for all the variants (will be in the next release and can be tried now with the snapshots).

Please don’t hesitate to tell us if you need any other clarification or help related to this.

@m-abyzov You could get the list of variants from theandroid extension, and configure a service for each, something like this:

apollo {
    android.applicationVariants.all {
        service(name) {
            packageName.set(...)
            srcDir(...)
        }
    }
}

This is essentially a simplified version of what createAllAndroidVariantServices does.

Removing the schema file declaration from the Apollo Gradle plugin configuration did the trick! 🤗 Everything now works as it should. Many thanks for the great support @martinbonnin! ❤️