question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unable to use client with ApolloProvider

See original GitHub issue

Intended 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:closed
  • Created 3 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

6reactions
benjamncommented, Oct 2, 2020

@johnneuland Have you tried importing ApolloProvider from @apollo/client instead of @apollo/react-hooks?

0reactions
KennedyKeinsteincommented, Aug 11, 2021

@johnneuland Have you tried importing ApolloProvider from @apollo/client instead of @apollo/react-hooks?

Thanks @johnneuland worked for me!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found