【发布时间】:2019-09-05 22:59:06
【问题描述】:
我正在尝试编写一个查询来检索具有属性linkedCards 的对象,其中包含具有不同架构的对象数组。
我有 3 种不同的架构(内置于 Contentful):
CardA 示例:
{
id: 42,
productName: 'Laptop',
price: 999
}
卡片示例:
{
id: 999,
title: 'Buy our refurbished Laptops today!'
}
CardC 示例:
{
id: 100,
linkedCards: [
{
id: 42,
productName: 'Laptop',
price: 999
},
{
id: 999,
title: 'Buy our refurbished Laptops today!'
}
]
}
查询:
allCardC() {
nodes {
linkedCards {
id
title
}
}
}
当我尝试运行以下 GraphQL 查询时,我得到
"Cannot query field "title" on type "CardACardBUnion". Did you mean to use an inline fragment on "CardA" or "CardB"?"
有没有内置的方法可以做到这一点,或者我可以以某种方式使用CardA 和CardB 的ID?也许有一个查询来获取linkedCards 中卡片的 ID,而另一个查询来获取所述卡片?
【问题讨论】:
标签: graphql gatsby graphql-js contentful