Recently I upgraded ApolloClient from the old version to v2.2.3. It seems that the requestHeaders is deprecated.
Which one should I use if I want to request with some customized headers?
apolloClient
.query(**Query(
para = paras
))
.requestHeaders(RequestHeaders
.builder()
.addHeader(CUSTOM_HEADER, requestId)
.build()
)
apolloCall.requestHeaders(..) has been deprecated in favor of apolloCall.toBuilder().requestHeaders(..).build()
This was made because it was easy to ignore the return value of requestHeaders in RxJava extensions and therefore have the headers ignored. See https://github.com/apollographql/apollo-android/issues/2430 for more background.
I can see how it makes chaining more verbose though, I'll try to think about improving this for a future version.
apolloCall.requestHeaders(..)has been deprecated in favor ofapolloCall.toBuilder().requestHeaders(..).build()
Thanks for your prompt reply.
Just for confirmation, apolloCall.requestHeaders(..) is only deprecated for ApolloQueryCall?
It should be deprecated for ApolloMutationCall as well. Sorry about that, a deprecated annotation slipped through the cracks there, I'll add it.
Thanks!
Unfortunately, ApolloMutationCall doesn't override toBuilder - which means that when you try to invoke mutation.toBuilder(), you get the behavior of ApolloCall.toBuilder(), which does not support using the request headers correctly. How difficult would it be to add the correct toBuilder override? (I'm not sure how deep that ends up reaching into the stack)
Alternately, since both ApolloQueryCall and ApolloMutationCall support the requestHeaders concept, this could be moved into ApolloCall potentially, although I'm sure that's more work. :-)
Yikes, good catch 馃憤 .
It turns out ApolloMutationCall and ApolloQueryCall are both internally implemented as RealApolloCall so adding the ApolloMutationCall.toBuilder declaration should be enough to resolve the appropriate builder. I wonder if it was possible to get a ApolloMutation.Builder from the public API before that.
I have edited https://github.com/apollographql/apollo-android/pull/2501 with ApolloMutationCall.toBuilder(). Let me know what you think.