I'm currently using Apollo's Android GraphQL client to interact with our GraphQL server. I have several queries and mutations defined in my graphql file. A couple of them return same data structure in the response. However, the code that's autogenerated by Apollo results in different data classes.
For example I have the following mutations:
mutation completeLogin(...) {
loginComplete(input: ...) {
login {
token {
access_token
refresh_token
}
}
}
}
mutation createPassword(...) {
createPassword(input: ...) {
login {
token {
access_token
refresh_token
}
}
}
}
The autogenerated classes for these are as follows:
data class CompleteLoginMutation{
//...
data class Login(
val token: Token
)
data class Token(
val access_token: String,
val refresh_token: String
)
}
data class CreatePasswordMutation{
//...
data class Login(
val token: Token
)
data class Token(
val access_token: String,
val refresh_token: String
)
}
I was expecting that Login
or Token
classes in these autogenerated classes were mapped to the same class as they are actually the same on the backend side. This is a problem while implementing mappers that convert data entities to domain entities. I need to implement the same mapper for these classes separately, resulting in further duplication. Is there a way to map the same query/mutation responses to the same autogenerated classes in GraphQL or may Apollo client be capable of such convenience?