I am trying to do authentication using Apollo Client and a token placed in header. I am trying something like this:
import { ApolloClient, createHttpLink, InMemoryCache } from '@apollo/client';import { setContext } from '@apollo/client/link/context';import { NormalizedCacheObject } from 'apollo-cache-inmemory';import { ApolloProvider } from '@apollo/react-hooks';...const httpLink = createHttpLink({ uri: 'https://graphql',});const authLink = setContext((_, { headers }) => { const token = 'XX'; return { headers: { ...headers, authorization: token ? `Bearer ${token}` : "", } }});const client = new ApolloClient({ link: authLink.concat(httpLink), cache: new InMemoryCache()});...<ApolloProvider client={client}><BrowserRouter><App /></BrowserRouter></ApolloProvider>
However, I keep getting a type error on Apollo Provider that:
Type 'ApolloClient<NormalizedCacheObject>' is missing the following properties from type 'ApolloClient<any>': store, writeData, initQueryManager
This makes the app crash. I am not manually using NormalizedCacheObject anywhere. How can I fix this?