(headers, token, initialState)
| 12 | }); |
| 13 | |
| 14 | function createClient(headers, token, initialState) { |
| 15 | let accessToken = token; |
| 16 | |
| 17 | (async () => { |
| 18 | // eslint-disable-next-line no-param-reassign |
| 19 | accessToken = token || (await persist.willGetAccessToken()); |
| 20 | })(); |
| 21 | |
| 22 | const authLink = new ApolloLink((operation, forward) => { |
| 23 | operation.setContext({ |
| 24 | headers: { |
| 25 | authorization: accessToken |
| 26 | } |
| 27 | }); |
| 28 | return forward(operation); |
| 29 | }).concat(httpLink); |
| 30 | |
| 31 | return new ApolloClient({ |
| 32 | headers, |
| 33 | link: authLink, |
| 34 | connectToDevTools: process.browser, |
| 35 | ssrMode: !process.browser, |
| 36 | cache: new InMemoryCache().restore(initialState || {}) |
| 37 | }); |
| 38 | } |
| 39 | |
| 40 | export default (headers, token, initialState) => { |
| 41 | if (!process.browser) { |
no test coverage detected