@@ -5,35 +5,24 @@ import App from './components/App'
5
5
import registerServiceWorker from './registerServiceWorker'
6
6
import { ApolloProvider } from 'react-apollo'
7
7
import { ApolloClient } from 'apollo-client'
8
- import { HttpLink } from 'apollo-link-http'
8
+ import { createHttpLink } from 'apollo-link-http'
9
9
import { InMemoryCache } from 'apollo-cache-inmemory'
10
10
import { BrowserRouter } from 'react-router-dom'
11
11
import { AUTH_TOKEN } from './constants'
12
- import { ApolloLink } from 'apollo-client-preset'
13
12
import { setContext } from 'apollo-link-context'
14
13
15
- const httpLink = new HttpLink ( { uri : 'http://localhost:4000' } )
16
- // const authLink = setContext((_, { headers }) => {
17
- // // get the authentication token from local storage if it exists
18
- // const token = localStorage.getItem('token')
19
- // // return the headers to the context so httpLink can read them
20
- // return {
21
- // headers: {
22
- // ...headers,
23
- // authorization: token ? `Bearer ${token}` : ''
24
- // }
25
- // }
26
- // })
14
+ const httpLink = createHttpLink ( {
15
+ uri : 'http://localhost:4000' ,
16
+ } )
27
17
28
- const authLink = new ApolloLink ( ( operation , forward ) => {
18
+ const authLink = setContext ( ( _ , { headers } ) => {
29
19
const token = localStorage . getItem ( AUTH_TOKEN )
30
- const authorizationHeader = token ? `Bearer ${ token } ` : null
31
- operation . setContext ( {
20
+ return {
32
21
headers : {
33
- authorization : authorizationHeader
22
+ ...headers ,
23
+ authorization : token ? `Bearer ${ token } ` : ''
34
24
}
35
- } )
36
- return forward ( operation )
25
+ }
37
26
} )
38
27
39
28
const client = new ApolloClient ( {
0 commit comments