I am using Apollo iOS client for doing GraphQL queries. I need to pass Auth token in the header which I am able to achieve using below code -
let apolloAuth: ApolloClient = {
            let configuration = URLSessionConfiguration.default
            let token = "Bearer \(UserDefaults.standard.string(forKey: "UserToken") ?? "")"
            // Add additional headers as needed
            configuration.httpAdditionalHeaders = ["Authorization": token]
            let url = URL(string: "...URL.../graphql")!
            return ApolloClient(networkTransport: HTTPNetworkTransport(url: url, configuration: configuration))
        }()
My fetch query goes as below -
apolloAuth.fetch(query: referralQuery){ (result, error) in
        if let error = error {
            print(error.localizedDescription)
            return
        }else{
            self.referralId = result?.data?.referrals?.id
        }
    }
Now my Server returns a refreshed auth token after every request which is a part of response header. I need to get the token from the response header but I am unable to find out a way to do that. Can someone guide me on this.
                        
Use interceptors for reading the tokens from the response header.
Sample code:
Reference: Creating a client