Marcelo Hernandez
05/10/2024, 3:39 PMquery
Boolean!
parameter on the request? For context, I have a fragment
that uses a conditional directive like so:
videos @include(if: $includeListingItemsVideos) {
id
}
And there are numerous queries that ultimately use this fragment
. I have updated all dependent queries to include:
$includeListingItemsVideos: Boolean! = false
If I omit the default value, modifying all entry points to explicitly pass in this Boolean
on the Kotlin side would require touching hundreds of files including tests.bod
05/10/2024, 4:00 PMApolloInterceptor
you can craft an ApolloRequest
with .newBuilder()
and pass a copy of the query with the desired value for the argument. But wouldn't the default value be nicer?Marcelo Hernandez
05/10/2024, 4:07 PMQuery1()
Query2()
Query3()
โฆ
QueryN()
I'm using the default value to avoid having to touch all N
instantiators of these queries because there are hundreds of them including unit tests that construct these.
Ultimately what I want is a centralized place where I can do:
if feature is enabled {
inspect if arbitrary operation has includeListingItemsVideos parameter
if so, set it to true before making the request
} else {
proceed as is (default value of false)
}
bod
05/10/2024, 4:16 PMMarcelo Hernandez
05/10/2024, 4:16 PMMarcelo Hernandez
05/10/2024, 4:18 PMsuspend
call) and then explicitly pass the Boolean
in. But as mentioned before, that would easily touch numerous files. Especially because we have a lot of unit tests that instantiate the Query models directly without using Data Builders or Test Builders.bod
05/10/2024, 4:19 PMMarcelo Hernandez
05/10/2024, 4:22 PMbod
05/10/2024, 4:27 PMclass MyInterceptor : ApolloInterceptor {
override fun <D : Operation.Data> intercept(request: ApolloRequest<D>, chain: ApolloInterceptorChain): Flow<ApolloResponse<D>> {
val operation = when (request.operation) {
is Query1 -> request.operation.copy(myArgument = Optional.present(true))
is Query2 -> request.operation.copy(myArgument = Optional.present(true))
else -> request.operation
}
return chain.proceed(request.newBuilder(operation).build())
}
}
a bit tedious as you'll have to do all the cases (one per query) but not sure there's a way around it... except maybe introspection, but that's a bit "hacky"Marcelo Hernandez
05/10/2024, 4:36 PMMarcelo Hernandez
05/10/2024, 4:37 PMrequest.operation.variables(CustomScalarAdapters.Empty)
but:
1. This is just a read-only map
2. The map does not include parameters with defaults that were not explicitly setbod
05/10/2024, 4:47 PMMarcelo Hernandez
05/10/2024, 4:48 PMmbonnin
05/10/2024, 10:09 PMmbonnin
05/10/2024, 10:10 PMmbonnin
05/10/2024, 10:12 PM