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
相关产品推荐
相关产品推荐

