ReactJS apolloClient 在上下文中找不到 "client" 或作为选项传入

ReactJS apolloClient Could not find "client" in the context or passed in as an option

我不明白为什么它会触发我这个问题,并且它在我的另一个应用程序中以相同的方式工作。我刚刚试了 3 天,我还没有弄清楚这个问题。

我在 Whosebug 上找到了这个解决方案:

但是没有解决我的问题

谁能帮我解决这个问题?

这是我的 App.js

import EmpTable from './components/empTable';
import { ApolloProvider } from '@apollo/react-hooks';


import { ApolloClient, InMemoryCache } from '@apollo/client';

const client = new ApolloClient({
  uri: 'http://localhost:8000/graphql/',
  cache: new InMemoryCache(),
});




function App() {
  return (
    <ApolloProvider client={client}>
        <EmpTable />
    </ApolloProvider>
  );
}

export default App;

这是我的员工表

import { gql, useQuery } from "@apollo/client";


function EmpTable() {

  const GET_EMPLOYEE = gql`
    query getEmp($id: String) {
      employeeById(id: $id) {
        id
        name
        role
      }
    }
  `;


  const {refetch} = useQuery(GET_EMPLOYEE)

  return (
    <div className="row">
      {/* some div  */}
    </div>
  );
}

export default EmpTable;

此代码出现以下错误:

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.
new InvariantError
src/invariant.ts:12
   9 | export class InvariantError extends Error {
  10 |   framesToPop = 1;
  11 |   name = genericMessage;
> 12 |   constructor(message: string | number = genericMessage) {
  13 |     super(
  14 |       typeof message === "number"
  15 |         ? `${genericMessage}: ${message} (see https://github.com/apollographql/invariant-packages)`
View compiled
invariant
src/invariant.ts:27
  24 |   message?: string | number,
  25 | ): asserts condition {
  26 |   if (!condition) {
> 27 |     throw new InvariantError(message);
  28 |   }
  29 | }
  30 | 

这个错误太长了,我只是把其中的几个放在这里。谁能告诉我到底是什么问题?

尝试从 @apollo/client

导入 ApolloProvider
import { ApolloProvider } from '@apollo/client';