Stylianos Gakis
01/11/2022, 9:25 AMoverride fun <D : Operation.Data> intercept(
request: ApolloRequest<D>,
chain: ApolloInterceptorChain,
): Flow<ApolloResponse<D>> {
return chain.proceed(request).map { response ->
if (notAplicableHere) return@map response // If nothing to intercept just return it as it was
// do something else with the response if applicable
response // ^map return the response as it was if we reached the end of the map
}
}
And in my case where I just want to do something but not edit the response itself maybe doing an onEach
is what I should look into?
...
return chain.proceed(request).onEach { response ->
if (response.notApplicablehere) return@onEach
//do something
}
I am now thinking this may have more to do with me not fully understanding how this flow chain would work, but I am pretty sure more people will have the same doubts so some guidance would be really appreciated (unless it’s in the docs and I missed it?)bod
01/11/2022, 9:46 AMoverride fun <D : Operation.Data> intercept(
request: ApolloRequest<D>,
chain: ApolloInterceptorChain,
): Flow<ApolloResponse<D>> {
if (notAplicableHere) return chain.proceed(request)
return chain.proceed(request).onEach { response ->
// your custom logic
}
}
Stylianos Gakis
01/11/2022, 10:14 AMApolloInterceptorFactory
which was added with addApplicationInterceptorFactory
, now we just add the interceptor itself, which makes me wonder if will this have any different behavior?
This migration process has me at the moment with the entire project being red pretty much and I can’t start testing what I am migrating until I get the project to build again, so I’m having a hard time knowing if what I’m doing is correct or not yet 😅mbonnin
01/11/2022, 10:17 AMFlow
introduction would simplify enough that the API would speak for itself but indeed coroutines API do change a lot of things...class SunsettingInterceptor: ApolloInterceptor {
override fun <D : Operation.Data> intercept(request: ApolloRequest<D>, chain: ApolloInterceptorChain): Flow<ApolloResponse<D>> {
return chain.proceed(request).onEach {
if (it.errors?.any { it.isSunsetError() } == true) {
ForceUpgradeActivity.newInstance(context)
}
}
}
private fun Error.isSunsetError(): Boolean {
return nonStandardFields?.get("errorCode") == "invalid_version"
}
}
Stylianos Gakis
01/11/2022, 10:29 AMmbonnin
01/11/2022, 11:12 AMCallback
API, maybe some other stuff so it might end up pulling a lot of code but it's worth exploring