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

Contentful API嵌套集合筛选:查询disabled为false的categoryList

Contentful嵌套集合查询过滤解决方案

Contentful的GraphQL API支持嵌套集合的过滤操作,但你之前的写法错误地将过滤条件放在了父级条目cfPageList的where参数中,正确的做法是把where参数直接添加到嵌套的categoryListCollection字段上——因为disabled是该集合内条目的字段。

修改后的完整查询如下:

query cfPageList(
  $contentfulLocale: String
  $entryId: String!
  $preview: Boolean = false
) {
  cfPageList(id: $entryId, locale: $contentfulLocale, preview: $preview) {
    sys {
      id
    }
    categoryListCollection(where: { disabled: false }) {
      options: items {
        value: value
        label: itemName
        disabled: disabled
      }
    }
  }
}

这样就能只返回categoryListCollection中disabled字段为false的项了。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.09 07:20:12