Intended outcome:
Trying to use the useMutation hook within a component. This component is nested within <ApolloProvider>. In fact, the useQuery hook works just fine, it's only useMutation that throw the errors.
Actual outcome:
The following error is immediately thrown when the react attempts to load (note, the resulting function is not run, the hook is just called):
Uncaught Invariant Violation: 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 tried to reproduce this on codesandbox.io but the maximum client it allowed was 2.6.4. I will attempt to reproduce via repo after I submit this.)
Using @apollo/[email protected] and @apollo/[email protected] create a minimal project with the <ApolloProvider> in please, then inside of a nested component attempt to call the useMutation hook.
Version
System:
OS: macOS 10.15.1
Binaries:
Node: 13.2.0 - /usr/local/bin/node
Yarn: 1.19.2 - /usr/local/bin/yarn
npm: 6.13.1 - /usr/local/bin/npm
Browsers:
Chrome: 78.0.3904.108
Firefox: 64.0.2
Safari: 13.0.3
This seems to be the same as this issue: https://github.com/apollographql/react-apollo/issues/3381
Turns out we were retrieving useMutation from @apollo/client instead of @apollo/react-hooks. 馃う鈥嶁檪
In my case I was using ApolloProvider "react-apollo" instead of '@apollo/react-hooks'
Most helpful comment
Turns out we were retrieving
useMutationfrom@apollo/clientinstead of@apollo/react-hooks. 馃う鈥嶁檪