Unable to use client with ApolloProvider
See original GitHub issueIntended outcome:
I should be able to use my client in the ApolloProvider component without an error.
Actual outcome:
Currently, I get this error. Even though I am simply following the Apollo docs.
Type 'ApolloClient<NormalizedCacheObject>' is missing the following properties from type 'ApolloClient<any>': store, writeData, initQueryManager
How to reproduce the issue:
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>
Versions
System: OS: macOS 10.15.5 Binaries: Node: 12.16.3 - /usr/local/bin/node Yarn: 1.22.5 - ~/.yarn/bin/yarn npm: 6.14.5 - /usr/local/bin/npm Browsers: Safari: 13.1.1 npmPackages: @apollo/client: ^3.2.1 => 3.2.1 @apollo/link-context: ^2.0.0-beta.3 => 2.0.0-beta.3 @apollo/react-hooks: ^4.0.0 => 3.1.5 apollo-boost: ^0.4.9 => 0.4.9 react-apollo: ^3.1.5 => 3.1.5
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Apollo GraphQL failing connection - Stack Overflow
My root component is already wrapped with an ApolloProvider tag, but the error message tells me it is not. Error Message Invariant Violation: ......
Read more >Get started with Apollo Client - Apollo GraphQL Docs
Our client is ready to start fetching data. Now before we start using Apollo Client with React, let's first try sending a query...
Read more >apollo/client - npm
Learn how to use Apollo Client with self-paced hands-on training on Odyssey, Apollo's official learning platform:
Read more >Why use Next.js with Apollo - LogRocket Blog
Use the Apollo Client with Next.js for caching support, ... Although you can't see data anywhere in the requested fields from the API, ......
Read more >Setting Up Apollo Client 3 with Nextjs - YouTube
... try restarting your device. Your browser can't play this video. ... Next video: GraphQL Pagination using Apollo Client and on the Server ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@johnneuland Have you tried importing
ApolloProvider
from@apollo/client
instead of@apollo/react-hooks
?Thanks @johnneuland worked for me!