Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/three.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs 客户端找不到";“客户”;在上下文中或作为选项传入_Reactjs_React Apollo_Apollo Client - Fatal编程技术网

Reactjs 客户端找不到";“客户”;在上下文中或作为选项传入

Reactjs 客户端找不到";“客户”;在上下文中或作为选项传入,reactjs,react-apollo,apollo-client,Reactjs,React Apollo,Apollo Client,我不明白为什么它要解雇我这个问题,它是以同样的方式在我的另一个应用程序之前。我刚刚试了三天,我还没弄明白这个问题 我在stackoverflow上找到了此解决方案: 但这并没有解决我的问题 有人能帮我解决这个问题吗 这是我的App.js import EmpTable from './components/empTable'; import { ApolloProvider } from '@apollo/react-hooks'; import { ApolloClient, InMemo

我不明白为什么它要解雇我这个问题,它是以同样的方式在我的另一个应用程序之前。我刚刚试了三天,我还没弄明白这个问题

我在stackoverflow上找到了此解决方案:

但这并没有解决我的问题

有人能帮我解决这个问题吗

这是我的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 EmpTable from./components/EmpTable';
从“@apollo/react hooks”导入{ApolloProvider};
从'@apollo/client'导入{apollo客户端,InMemoryCache};
const客户端=新客户端({
uri:'http://localhost:8000/graphql/',
缓存:新的InMemoryCache(),
});
函数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;
import{gql,useQuery}来自“@apollo/client”;
函数可空(){
const GET_EMPLOYEE=gql`
查询getEmp($id:String){
employeeById(id:$id){
身份证件
名称
角色
}
}
`;
const{refetch}=useQuery(获取员工)
返回(
{/*某些div*/}
);
}
导出默认为空;
此代码出现以下错误:

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 | 
在上下文中找不到“客户端”,或作为选项传入。将根组件包装到中,或通过选项将客户端实例传递到中。
新不变量误差
src/invariant.ts:12
9 |导出类不变量错误扩展错误{
10 | framesToPop=1;
11 | name=通用消息;
>12 |构造函数(消息:string | number=genericMessage){
13 |超级(
14 |信息类型==“编号”
15 |?`${genericMessage}:${message}(参见https://github.com/apollographql/invariant-packages)`
视图编译
不变的
src/invariant.ts:27
24 |消息?:字符串|编号,
25 |):断言条件{
26 |如果(!条件){
>27 |抛出新的不变量错误(消息);
28 |   }
29 | }
30 | 

错误太长了,我只在这里输入了几个。有人能告诉我问题的具体内容吗?

请尝试从
@apollo/client
导入
ApolloProvider

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

尝试从
@apollo/client

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