Apollo-android: Trying to set up in multi module project. Getting error in generated file

Created on 16 Jan 2021  路  5Comments  路  Source: apollographql/apollo-android

Summary
Trying to set up in multi module project. Getting error in generated file

Version
2.5.2

Description
I'm trying to set up apollo in multi module project following this guide. I have added generateApolloMetadata.set(true) in shared module. After executing task: generateApolloSources in shared module, I'm getting errors in some of the generated files. Code in generated file looks like this:

data class SomeClassNameInput(
  val someFieldName: Input<List<SomeObject?>> = Input.optional(listOf("null"))
) : InputType {
...

error description:

Type mismatch:
required: List<SomeObject?>
found:    List<String>

If I remove generateApolloMetadata.set(true) from shared.gradle and run task: generateApolloSources again, files with errors described above are gone

Bug

All 5 comments

Hi 馃憢 ! It looks like one of the default values for someFieldName is badly interpreted. This is most likely due to bug https://github.com/apollographql/apollo-android/issues/2727

My guess is that this is happening when enabling multi-module because multi-module generates all input types. From https://www.apollographql.com/docs/android/advanced/multi-modules/#big-schemas:

When using multiple modules, Apollo Android will generate all possible Input Types and Enums
 in the root module, and not only the used ones. This is because there is no way to know from
 the parent module what types are going to be used in feature modules. 

When you disable multi-module, SomeClassNameInput doesn't get generated and therefore there's no compilation error.

As a workaround, until #2727 is fixed, you can set alwaysGenerateTypesMatching.set(emptyList()) in your gradle configuration and that should remove the class again.

Thanks for quick reply @martinbonnin
adding alwaysGenerateTypesMatching.set(emptyList()) is causing following error:

A problem occurred evaluating project ':shared'.
> No signature of method: build_c1qwmpqlc6r6vqxxulke2kb7j.android() is applicable for argument types: (build_c1qwmpqlc6r6vqxxulke2kb7j$_run_closure1) values: [build_c1qwmpqlc6r6vqxxulke2kb7j$_run_closure1@1c3b9d20]

Any idea how to fix it?

Looks like you're using Groovy build.gradle files? alwaysGenerateTypesMatching.set(emptyList()) is for Kotlin Gradle build scripts. My Groovy is a bit rusty but something like below should do it:

alwaysGenerateTypesMatching = []

Hi @nmaruashvili ! Did that work? Mind if I close this one and we keep #2727 for the default values bug?

Yes, you can close this one. alwaysGenerateTypesMatching = [] resolved my problem. Thank you again.

Was this page helpful?
0 / 5 - 0 ratings