我想知道具有 id 属性的对象类型是否必须在给定相同 id 的情况下具有相同的内容。目前同一个id可以有不同的内容。
以下查询:
const query = gql`
query products(
$priceSelector: PriceSelectorInput!
) {
productProjectionSearch(
priceSelector: $priceSelector
) {
total
results {
masterVariant {
# If you do the following it will work
# anythingButId: id
id
scopedPrice {
country
}
}
}
}
}
`;
如果PriceSelectorInput
是,{currency: "USD", country: "US"}
那么结果是:
{
"productProjectionSearch": {
"total": 2702,
"results": [
{
"name": "Sweater Pinko white",
"masterVariant": {
"id": 1,
"scopedPrice": {
"country": "US",
"__typename": "ScopedPrice"
},
"__typename": "ProductSearchVariant"
},
"__typename": "ProductProjection"
}
],
"__typename": "ProductProjectionSearchResult"
}
}
如果PriceSelectorInput
是,{currency: "EUR", country: "DE"}
那么结果是:
{
"productProjectionSearch": {
"total": 2702,
"results": [
{
"name": "Sweater Pinko white",
"masterVariant": {
"id": 1,
"scopedPrice": {
"country": "DE",
"__typename": "ScopedPrice"
},
"__typename": "ProductSearchVariant"
},
"__typename": "ProductProjection"
}
],
"__typename": "ProductProjectionSearchResult"
}
}
我的问题是,ProductSearchVariant 类型的 masterVariant 在这两种情况下的 id 都是 1,但 scopedPrice 的值不同。这会破坏 apollo 缓存 defaultDataIdFromObject 函数,如本 repo中所示。我的问题是;这是 apollo 中的错误还是违反了 ProductSearchVariant 类型定义中的 graphql 标准?