2
votes

I'm trying to use apollo-android library to communicate with graphql server. The problem is that backend uses headers to authenticate requests and I found no ways to add them. Also in auth request the token is sent in headers and I found no ways to read it from the response.

People advise to set auth headers via interceptors in OkHttpClient but this approach is not applicable in my situation because client have to send different sets of headers in different requests.

So, is there any workaround in this situation? Should I use simple rest client like Retrofit or maybe create new ApolloClient and OkHttpClient instances on each new request with desired set of headers? Or maybe there is another workarounds?

1
Are you looking for syntax explaining how to add RequestHeaders to graphql query/mutation?itabdullah

1 Answers

0
votes

People advise to set auth headers via interceptors in OkHttpClient but this approach is not applicable in my situation because client have to send different sets of headers in different requests.

Have setter methods and fields on your interceptors that accept the varying headers. Call those setter methods prior to making an ApolloClient request that needs the headers.

Or, teach the interceptor how to apply different headers for different requests based on the request characteristics visible to the interceptor (e.g., URL).