小编use*_*991的帖子

如何将 apollo 客户端 fetchMore updateQuery 转换为 apollo 缓存合并功能?

我正在学习 apollo 和 graphQL,并且有一个简单的应用程序,它显示一个数据列表,带有一个添加到数组的 fetchMore 函数。

我想删除 updateQuery,因为它已被弃用并使用新的字段策略合并功能。当前缓存设置和 updateQuery 如下所示:

const cache = new InMemoryCache({
  typePolicies: {
    client_client: {
      fields: {
        // add local only value to clients
        isEdited: {
          read(value = false) {
            // when writing the new value return new value or false as default
            return value;
          },
        }
      }
    }
  }
});
Run Code Online (Sandbox Code Playgroud)
  const onFetchMore = () => {
    fetchMore({
      variables: {
        offset: page
      },
      updateQuery: (previousResult, { fetchMoreResult, queryVariables }) => {
        return {
          ...previousResult,
          client_client: [ …
Run Code Online (Sandbox Code Playgroud)

apollo graphql react-apollo apollo-client

5
推荐指数
1
解决办法
670
查看次数

标签 统计

apollo ×1

apollo-client ×1

graphql ×1

react-apollo ×1