mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-05-11 05:05:07 -05:00
36 lines
829 B
JavaScript
36 lines
829 B
JavaScript
import React from 'react'
|
|
import ReactDOM from 'react-dom'
|
|
import App from './App'
|
|
import { ApolloProvider } from 'react-apollo-hooks'
|
|
import { ApolloClient } from 'apollo-client'
|
|
import { createHttpLink } from 'apollo-link-http'
|
|
import { InMemoryCache } from 'apollo-cache-inmemory'
|
|
import { setContext } from 'apollo-link-context'
|
|
|
|
const httpLink = createHttpLink({
|
|
uri: '/graphql',
|
|
})
|
|
|
|
const authLink = setContext((_, { headers }) => {
|
|
|
|
const token = localStorage.getItem('user-token')
|
|
return {
|
|
headers: {
|
|
...headers,
|
|
authorization: token ? `bearer ${token}` : null,
|
|
}
|
|
}
|
|
})
|
|
|
|
const client = new ApolloClient({
|
|
link: authLink.concat(httpLink),
|
|
cache: new InMemoryCache()
|
|
})
|
|
|
|
ReactDOM.render(
|
|
<ApolloProvider client={client}>
|
|
<App />
|
|
</ApolloProvider>,
|
|
document.getElementById('root')
|
|
)
|