kandimat/redaktions-app/src/backend/helper.ts
Christoph Lienhard fc8bc6724b
#11 Refactor: Introduce apollo reactive variables for global state
Use it to streamline entangle the delete dialog(s) from the list(s)
2020-12-30 18:26:19 +01:00

24 lines
564 B
TypeScript

import {ApolloClient, createHttpLink, InMemoryCache} from "@apollo/client";
import {setContext} from "@apollo/client/link/context";
const httpLink = createHttpLink({
uri: 'http://localhost:5433/graphql',
});
const authLink = setContext((_, { headers }) => {
const token = localStorage.getItem('token');
return token ? {
headers: {
...headers,
authorization: `Bearer ${token}`,
}
} : headers
});
export const client = new ApolloClient({
cache: new InMemoryCache(),
link: authLink.concat(httpLink),
connectToDevTools: true,
});