1

我需要区分具有相同 __typename (Union) 的两个查询,以使 Apollo Client typePolicies 缓存正常工作。

联盟也是如此RelatedNodes,我没有从服务器获得唯一标识符字段。

nodes由一个称为 的字段来区分type。查看查询:

query GetNodesTypeOne($limit: Int, $offset: Int,) {
  getNodesTypeOne(limit: $limit, offset: $offset) {
    __typename
    nodes {
      uuid
      type
      title
    }
  }
}

我想使用该字段nodes.type创建一个唯一标识符,我可以在keyFields属性中使用它(如keyFields: ['type'])。

Apollo 客户端typePolicies配置如下:

typePolicies: {
    RelatedNodes: {
      keyFields: [],
      fields: {
        nodes: offsetLimitPagination(),
      },
    },
  },

我正在尝试什么:

在我的查询中添加一个仅限本地的字段:

   query GetNodesTypeOne($limit: Int, $offset: Int,) {
      getNodesTypeOne(limit: $limit, offset: $offset) {
        type @client // the field a want to use in the typePolicies
        nodes {
          uuid
          type
          title
        }
      }
    }

然后使用 Apollo Client读取功能,我想创建一个type字段来获取它的值nodes.type

那可能吗?

4

0 回答 0