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