You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Contentful GraphQL 多引用(references, many)字段关联过滤查询实现方法

Contentful 多引用字段关联查询方案

该需求可以正常实现,针对多引用(references, many)类型的字段,你可以直接使用多引用对应的集合字段作为过滤条件入口,语法如下:

export const NEWS_ARTICLES = gql`
    query GetNewsArticles($location: String) {
        entryCollection(
            where: {
                # 替换为你的多引用字段对应的集合名,你提到的schema中为locationCollection
                locationCollection: { 
                    city: $location 
                }
            }
        ) {
            items {
                locationCollection {
                    items {
                        city
                        # 其他需要返回的位置字段
                    }
                }
            }
        }
    }
`;
  • 上述查询的过滤逻辑为:返回所有locationCollection多引用字段中至少存在一个关联位置条目,其city属性等于传入的$location参数的父条目,完全匹配你的查询需求。
  • 你在schema中看到的locationCollection_exists参数是用来过滤多引用字段是否为空的,不需要使用该参数也可以实现关联属性过滤。

内容的提问来源于stack exchange,提问作者Johnny Kontrolletti

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.03 21:27:01