I am setting up a new typescript project with react and apollo client. I am attempting to wire in the client like so:
const client = new ApolloClient({
cache: new InMemoryCache(),
link: new HttpLink({
uri: 'http://localhost:3000/graphql',
headers: {
authorization: localStorage.getItem('token'),
},
}),
});
function App() {
return (
<ApolloProvider client={client}>
<div className="App">
...content goes here
</div>
</ApolloProvider>
);
}
However, this throws an error during runtime:
TypeScript error in /src/App.tsx(60,21):
Property 'setLink' is missing in type 'ApolloClient<NormalizedCacheObject>' but required in type 'ApolloClient<any>'. TS2741
58 | function App() {
59 | return (
> 60 | <ApolloProvider client={client}>
| ^
61 | <div className="App">
As this appears to be a type based problem, I attempted to be explicit when creating the Apollo client per the example here: https://github.com/apollographql/apollo-client/issues/2503
const client = new ApolloClient<NormalizedCacheObject>{ ...
But no dice. I'm not sure why I have dueling types compared to working examples. Help?