【发布时间】:2018-04-06 22:12:01
【问题描述】:
我们的 GraphQL 服务器使用包含对象数组的数据响应查询,每个对象共享相同的 id 和不同键的不同值。例如,我们可能有一个如下所示的数组:
[
{ id: 123, name: 'foo', type: 'bar', cost: 5 },
{ id: 123, name: 'foo', type: 'bar', cost: 6 },
{ id: 123, name: 'foo', type: 'bar', cost: 7 },
{ id: 123, name: 'foo', type: 'bar', cost: 8 }
]
我们可以在“网络”选项卡中看到来自服务器的响应中包含正确的数据。然而,当它经过 Apollo 客户端模块的处理时,该数组已被转换为如下所示的东西:
[
{ id: 123, name: 'foo', type: 'bar', cost: 5 },
{ id: 123, name: 'foo', type: 'bar', cost: 5 },
{ id: 123, name: 'foo', type: 'bar', cost: 5 },
{ id: 123, name: 'foo', type: 'bar', cost: 5 }
]
基本上我们看到的是,如果数组中的所有对象共享相同的 id 值,那么数组中的所有对象都将成为数组中第一个对象的副本。
这是 Apollo Client 的预期行为吗?我们认为这可能与不正确的缓存有关,但我们也想知道 Apollo 客户端是否假设具有相同 id 的后续数组成员是同一个对象。
【问题讨论】:
标签: javascript graphql apollo-client