apollographql / apollo-ios

📱  A strongly-typed, caching GraphQL client for iOS, written in Swift.
https://www.apollographql.com/docs/ios/
MIT License
3.88k stars 726 forks source link

How can I set custom header to specific request #284

Closed wsof401 closed 6 years ago

wsof401 commented 6 years ago

Here is some cases we are facing in our app.

  1. When user login app, we need add token to specific request header

    Now we build new apolloClient, but our token expiration is 15mins, We will build a new client frequently

  2. For some reason, some custom header should be add to the request.

    We haven‘t found a good solution for case 2

Is apollo-ios support it? URLProtocol is a solution but not a good one

paulemmanuel-garcia commented 6 years ago

Hello,

I'm just starting with Apollo on iOS, so I'm not 100% sure and it might not be the recommended way of doing.

Actually you can initialize the ApolloClient with:

init(url: URL, configuration: URLSessionConfiguration = URLSessionConfiguration.default, sendOperationIdentifiers: Bool = false)

So you can set some custom headers with the URLSessionConfiguration. This will be done to all your requests though.

Hope it can be helpful.

wsof401 commented 6 years ago

@paulemmanuel-garcia no, It only worked when the first time you set it

jobnte commented 6 years ago

Did you found any solution for this?

wsof401 commented 6 years ago

@jorgelub12 Yes, A client for addtional headers in memory