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

Wagtail Grapple中按分类ID/Slug查询博客的GraphiQL语句求助

通过分类ID或Slug查询指定分类下的博客内容(Wagtail Grapple)

你的BlogPage已经通过@register_paginated_query_field("blogpage")注册了分页查询字段,且在graphql_fields中定义了categories与Category模型的关联,因此可以通过GraphiQL的过滤条件筛选指定分类下的博客内容,以下是两种查询方式:

1. 通过分类ID查询

将your-category-id-here替换为目标分类的实际ID,可按需调整page和perPage分页参数:

query {
  blogpage(
    filter: {
      categories: {
        id: "your-category-id-here"
      }
    }
    page: 1
    perPage: 10
  ) {
    items {
      id
      title
      subtitle
      introduction
      datePublished
      imageUrl
      categories {
        id
        name
        slug
      }
      authors {
        id
        name
      }
    }
    pagination {
      total
      count
      perPage
      currentPage
      totalPages
    }
  }
}

2. 通过分类Slug查询

将your-category-slug-here替换为目标分类的实际Slug,分页参数可灵活调整:

query {
  blogpage(
    filter: {
      categories: {
        slug: "your-category-slug-here"
      }
    }
    page: 1
    perPage: 10
  ) {
    items {
      id
      title
      subtitle
      introduction
      datePublished
      imageUrl
      categories {
        id
        name
        slug
      }
      authors {
        id
        name
      }
    }
    pagination {
      total
      count
      perPage
      currentPage
      totalPages
    }
  }
}

注意事项

  • 确保base.Category模型已配置对应的GraphQL字段(如id、name、slug),否则无法用于过滤或返回分类信息。
  • 若需匹配多个分类,可使用in操作符,示例:slug: { in: ["tech", "lifestyle"] }

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.16 01:23:16