Sign in
Log inSign up
Dhaiwat Pandya

27 likes

·

1.1K reads

2 comments

Idris Olubisi
Idris Olubisi
Jul 20, 2022

Thanks for sharing Dhaiwat Pandya

·
Sumit Mahajan
Sumit Mahajan
Sep 25, 2022

The apollo client configuration seems to be changed a bit now.

import {
  ApolloClient,
  createHttpLink,
  gql,
  InMemoryCache,
} from "@apollo/client";
import { setContext } from "@apollo/client/link/context";

const API_URL = "YOUR_URL";

const httpLink = createHttpLink({ uri: API_URL });

const authLink = setContext((_, { headers }) => {
  const token = localStorage.getItem("access_token");

  return {
    headers: {
      ...headers,
      "x-access-token": token ? `Bearer ${token}` : "",
    },
  };
});

export const apolloClient = new ApolloClient({
  link: authLink.concat(httpLink),
  cache: new InMemoryCache(),
});
·