Vagner Wentz
Vagner Wentz

Reputation: 566

GraphQL: Could not find "client" in the context or passed in as an option

I'm developing a web site with React and Apollo but throw the error. I saw that can be something about hierarchy

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.

index.tsx

import React from 'react';
import ReactDOM from 'react-dom';
import { ApolloProvider } from 'react-apollo';

import graphqlClient from './services/graphql';
import App from './App';

import 'bootstrap/dist/css/bootstrap.min.css';

ReactDOM.render(
  <ApolloProvider client={graphqlClient}>
    <App />,
  </ApolloProvider>,
  document.getElementById('root'),
);

App.tsx

import React from 'react';
import { BrowserRouter as Router } from 'react-router-dom';

import GlobalStyle from './styles/global';

import Routes from './routes';

const App: React.FC = () => {
  return (
    <Router>
      <Routes />
      <GlobalStyle />
    </Router>
  );
};

export default App;

package.json

enter image description here

Upvotes: 0

Views: 577

Answers (1)

Jedavard
Jedavard

Reputation: 119

Make sure you have correctly set up the apollo client in "./services/graphql". For more information I have to take a look on that module.

You use previous apollo client. If you start a new project, better to start with the latest one. https://www.apollographql.com/docs/react/

Upvotes: 1

Related Questions