configureClient.ts 749 Bytes
import * as R from "ramda";
import { ApolloLink } from "apollo-link";
import { setContext } from "apollo-link-context";
import { InMemoryCache } from "apollo-cache-inmemory";
import { ApolloClient } from "apollo-client";
import { createUploadLink } from "apollo-upload-client";

const authLink = setContext((req, { headers }) => {
  const token = localStorage.getItem("token");
  const authorization = token ? `Bearer ${token}` : "";
  return { headers: R.merge(headers, { authorization }) };
});
const uploadLink = createUploadLink();

const link = ApolloLink.from([authLink, uploadLink]);

const cache = new InMemoryCache({
  cacheRedirects: {
    Query: {}
  }
});

const client = new ApolloClient({ link, cache });

export default () => client;