While working on mutations I see the following error.
Cause: duplicate Type 'ResolverKey(kind=SchemaType, id=Mutation)' generated in modules: modula-a, module-b
Use 'alwaysGenerateTypesMatching' in a parent module to generate the type only once
I also see error related to Mutation$Companion.dex
Type com.domain.android.shared.type.Mutation$Companion is defined multiple times:
Triage
- On checking the generated code in both the modules in question, I noticed the
Mutation.kt
has been generated in both the modules’ build/generated/source/apollo/shared.type folder and the package for both the files is the same. i.e package com.domain.android.shared.type
- I’ve checked that the feature modules in question have their respective apollo packages set.
App Setup
I can probably explain the setup of our app.
So the graphql schema.json
file is present in a shared
module and the dependency for this shared module has been added to the respective feature module’s build.gradle file.
Is there anything else that I should be looking at to fix this error?
Ok so here’s what I did to resolve this issue on my end.
I added Mutation
to the alwaysGenerateTypesMatching.set
in the shared module’s build.gradle along with the rest of the Apoll-Kotlin configurations that we have.
apollo {
generateApolloMetadata.set(true) // Required for multimodule support
useVersion2Compat()
alwaysGenerateTypesMatching.set(["
"Query",
"Mutation"])
customScalarsMapping = [ "Date" : "java.time.OffsetDateTime"]
}
After adding this I Inavlidated the cache & restarted Android studio.
Just to be sure I deleted all the sub-directories in the build/.transforms
folder.
Let me know if this worked for anyone else facing this issue.
Hi!
Thank you for reporting this!
alwaysGenerateTypesMatching
is needed when several modules reference in an operation a type from a shared schema, which would normally generate the related class in each module - causing clash issues.
However I’m surprised to see this happen to the Mutation
type. This is normally needed only for things like enums, inputs, scalars.
Could you share the relevant parts of your schema / operations so we can investigate on what’s happening? Thanks!
1 Like
However I’m surprised to see this happen to the Mutation
type. This is normally needed only for things like enums, inputs, scalars.
Nevermind that part, it turns out it’s actually expected, and using alwaysGenerateTypesMatching
is correct. When at least one mutation (same principle for queries) is present in the shared module, the corresponding class will be generated there, but if not, then you’ll need it.
1 Like
Turns out even after Invalidating the cache & restarting Android Studio, I would still have to delete all the sub-directories from the build/.transforms
directory of the modules in question.
I would still have to delete all the sub-directories from the build/.transforms
You’ve most likely hit this AGP issue. It was fixed in 7.3 and backported to 7.1 and 7.2 but not sure what version anymore but if you update all your AGPs you should have the fix.
1 Like