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.

Could not find "client" in the context of Apollo(MyComponent). Wrap the root component in an <ApolloProvider>

See original GitHub issue

I am getting this error while doing testing. I think it coming because I am testing a component which Query render props and one of child component is using useQuery and useMutation. Are they way to fix this ? or I have to convert that component into hooks/vice-versa

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:10

github_iconTop GitHub Comments

6reactions
antonbehaeghecommented, Jul 1, 2019

react apollo offers a MockedProvider - would it be an idea to add a MockedHooksProvider to this package?

2reactions
jzabalacommented, Jun 14, 2019

Hi @Enigma10

If you are testing a component that use useQuery or useMutation you need to wrap the component with the ApolloProvider. You can check an example here: https://github.com/trojanowski/react-apollo-hooks-sample-test/blob/master/src/__tests__/Hello-test.js

If I understood your case correctly you are using both: react-apollo and react-apollo-hooks at the same time so, I think you’ll need to wrap your component with both providers. Check how to use the mock provider for react-apollo here: https://www.apollographql.com/docs/react/recipes/testing/

Read more comments on GitHub >

github_iconTop Results From Across the Web

Could not find "client" in the context or passed in as an option ...
Wrap the root component in an <ApolloProvider>, or pass an ApolloClient instance in via options. How to reproduce the issue: I have a...
Read more >
React Apollo Error: Invariant Violation: Could not find "client ...
Invariant Violation : Could not find "client" in the context or passed in as an option. Wrap the root component in an ,...
Read more >
Accessing Apollo client in an Astro + React project without ...
If I try I get this error: Could not find “client” in the context or passed in as an option. Wrap the root...
Read more >
Apollo and Graphql Help: "Could not find "client" in the context ...
Wrap the root component in an <ApolloProvider>, or pass an ApolloClient instance in via options." As of right now, my goal is to...
Read more >
React Apollo Error: Invariant Violation: Could not find "client ...
Coding example for the question React Apollo Error: Invariant Violation: Could not find "client" in the context or passed in as an option-Reactjs....
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