mirror of
https://github.com/hazemKrimi/crimson-quirks-ui.git
synced 2026-05-02 02:30:29 +00:00
Update apollo config
This commit is contained in:
+23
-5
@@ -1,6 +1,12 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import ReactDOM from 'react-dom';
|
import ReactDOM from 'react-dom';
|
||||||
import { ApolloClient, InMemoryCache, ApolloProvider } from '@apollo/client';
|
import {
|
||||||
|
ApolloClient,
|
||||||
|
InMemoryCache,
|
||||||
|
createHttpLink,
|
||||||
|
ApolloProvider,
|
||||||
|
} from '@apollo/client';
|
||||||
|
import { setContext } from '@apollo/client/link/context';
|
||||||
import { ThemeProvider } from 'styled-components';
|
import { ThemeProvider } from 'styled-components';
|
||||||
import { BrowserRouter } from 'react-router-dom';
|
import { BrowserRouter } from 'react-router-dom';
|
||||||
import { theme } from './themes';
|
import { theme } from './themes';
|
||||||
@@ -8,12 +14,24 @@ import App from './App';
|
|||||||
import GlobalStyles from './GlobalStyles';
|
import GlobalStyles from './GlobalStyles';
|
||||||
import reportWebVitals from './reportWebVitals';
|
import reportWebVitals from './reportWebVitals';
|
||||||
|
|
||||||
const client = new ApolloClient({
|
const httpLink = createHttpLink({
|
||||||
uri: process.env.REACT_APP_GRAPHQL_API,
|
uri: process.env.REACT_APP_GRAPHQL_API,
|
||||||
|
});
|
||||||
|
|
||||||
|
const authLink = setContext((_, { headers }) => {
|
||||||
|
const token = localStorage.getItem('token');
|
||||||
|
|
||||||
|
return {
|
||||||
|
headers: {
|
||||||
|
...headers,
|
||||||
|
authorization: token || '',
|
||||||
|
},
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
const client = new ApolloClient({
|
||||||
|
link: authLink.concat(httpLink),
|
||||||
cache: new InMemoryCache(),
|
cache: new InMemoryCache(),
|
||||||
headers: {
|
|
||||||
authorization: localStorage.getItem('token')!,
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
|
|
||||||
ReactDOM.render(
|
ReactDOM.render(
|
||||||
|
|||||||
Reference in New Issue
Block a user