Is there some built-in or just an easy way to trac...
# apollo-kotlin
w
Is there some built-in or just an easy way to track queries that got
PERSISTED_QUERY_NOT_FOUND
error? Just something for logging purposes
I thought maybe
setAutoPersistedOperationsInterceptorFactory
will help, but it seems like setting it overwrites the one set by
enableAutoPersistedQueries(true)
. I suppose I could create my own interceptor that wraps
ApolloAutoPersistedOperationInterceptor
?
Doesn’t look like I can hook into the proper callback when wrapping, instead I’d have to reimplement the entire APQ functionality 😢
m
Mmm yea APQ happens quite late in the interceptor chain so any "regular" interceptor will most likely not see the
PERSISTED_QUERY_NOT_FOUND
Let me see if that can be done somehow
w
Yea regular ones don’t see it, and OkHttp-ones are a bit early on the other hand, so I’d have to read and parse the response body manually
m
Yea, you'd need something in between
ApolloAutoPersistedOperationInterceptor
and
ApolloParseInterceptor
🤔
👌 1
w
Btw it was kind of surprising to see the
set..factory
overwrite
enable…
option, I thought it was some additional factory exactly to provide some additional listeners or in any way hook into apq flow
m
Yea that API is clunky
Looks like I should have gone the
setInterceptorFactories
route there instead but with all this code being ultimately moved to Kotlin, I'm not thrilled at the idea at changing this
w
fwiw my use case is not that important, although nice to have. I just want to log warnings if apq hash is not found on the server, otherwise it’d be difficult to monitor if the feature is working properly in production
And we already misconfigured apq on the server once 😄
A bandaid solution would be to provide
Factory(boolean useHttpGet, boolean persistQueries, boolean persistMutations, SomeCallback listener)
constructor and let me create the factory manually, providing custom listener, instead of using
enableApq(true)
. This seems kind of like a band-aid api though
m
Could you copy/paste the 143 lines of
ApolloAutoPersistedOperationInterceptor.java
? Maybe even copy/paste it in Kotlin, that'll be even less lines 😅
I know that doesn't feel great but it's not terrible either
w
Yea I can just copy the class, seems like it’s the easiest way 🙂
m
This API should change much until 3.0. And hopefully this will be easier to achieve with 3.0
👍 1
w
I ended up creating Apollo’s factory but discarding the provided
logger
and passing an adapter that logs to our infrastructure 🙂 The built-in implementations logs exactly what I want anyway
Copy code
internal class ApqInterceptorFactory : ApolloInterceptorFactory {

    private val wrapped = ApolloAutoPersistedOperationInterceptor.Factory(false, true, true)
    private val loggerAdapter = ApolloLogger(ApolloLoggerToLogAdapter())

    override fun newInterceptor(logger: ApolloLogger, operation: Operation<*, *, *>) =
        wrapped.newInterceptor(loggerAdapter, operation)
}
👍 1
In the end logger adapter is bigger than this wrapper 😄
😅 1