Hello everyone. I've been struggling with this issue for two days. It seems, Dagger2 not recognized Apollo's autogenerated model classes.
Here is my ApiService, injects apollo client and makes query observable.
class ApiService @Inject constructor(private var apolloClient: ApolloClient) {
//Not works with PokemonRepositoryQuery.Pokemon
fun getPokemons(count: Int): Observable<List<PokemonRepositoryQuery.Pokemon>> {
return Rx2Apollo.from(apolloClient.query(PokemonRepositoryQuery.builder().first(count).build())).map {
it.data()?.pokemons()
}
}
}
Error log
[ComponentProcessor:MiscError] dagger.internal.codegen.ComponentProcessor was unable to process this class because not all of its dependencies could be resolved. Check for compilation errors or a circular dependency with generated code.
public final class ApiService {
But if I use with my own Model class, like below, it works as expected.
class ApiService @Inject constructor(private var apolloClient: ApolloClient) {
// Works with my own model
private val mapper = PokemonMapper()
fun getPokemons(count: Int): Observable<List<Pokemon>> {
return Rx2Apollo.from(apolloClient.query(PokemonRepositoryQuery.builder().first(count).build())).map {
it.data()?.pokemons()?.map {
mapper.mapToPokemon(it)
}
}
}
}
My Query
query PokemonRepository($first:Int!){
pokemons(first:$first) {
id
image
name
}
}
But as you think, I don't want to create my own model. That is why I'm learning Graphql :)
Any ideas ?
Thanks
I've just tried .Didn't worked :/
Found the solution! I was wrong. I put the my .graphql and schema.json under graphql folder. I was working and Android Studio was recognizing. But If you want to use with Dagger2, you must put them under the graphql/{yourpackagename}/.graphql file. Otherwise, dagger2 won't recognize them.
Thanks
confirm, rootPackageName.set("com.packagename") in gradle file solved the problem
Most helpful comment
Found the solution! I was wrong. I put the my .graphql and schema.json under graphql folder. I was working and Android Studio was recognizing. But If you want to use with Dagger2, you must put them under the graphql/{yourpackagename}/.graphql file. Otherwise, dagger2 won't recognize them.
Thanks