【问题标题】:ApolloClient reducer is not a functionApolloClient reducer 不是函数
【发布时间】:2018-09-14 19:29:03
【问题描述】:

我正在使用 apolloClient 向 graphql 服务器发送请求。

然而,由于我的应用程序使用 Redux,我遵循此文档 apollo-redux 能够使用 Redux 实现 apollo 客户端。

这是我客户的代码:

const client = new ApolloClient();

const store = createStore(
  combineReducers({
    apollo: client.reducer(),
    // others
  })

然而,client.reducer() 行会引发错误

client.reducer 不是函数

我该如何纠正这个错误

【问题讨论】:

  • 你用的是什么版本的阿波罗?
  • 它是 2.1.1 - 最后一个

标签: redux apollo react-apollo


【解决方案1】:

由于从 2.0 开始,redux 没有被用作 Apollo 的缓存,您现在应该使用提供的 Apollo 存储:

import { ApolloProvider } from "react-apollo";

const App = () => (
  <ApolloProvider client={client}>
    <div>
      <h2>My first Apollo app ?</h2>
    </div>
  </ApolloProvider>
);

https://www.apollographql.com/docs/react/recipes/2.0-migration.html#redux

【讨论】:

  • 但是 redux 商店呢?我应该修改我的所有应用程序以使用 apollo 商店而不是 redux 吗?
猜你喜欢
  • 2018-04-27
  • 2019-07-08
  • 2018-11-10
  • 1970-01-01
  • 1970-01-01
  • 2018-10-18
  • 1970-01-01
  • 2019-02-20
  • 2021-04-28
相关资源
最近更新 更多