简体   繁体   English

Strapi & graphql:如何获得项目总数?

[英]strapi & graphql : how to get total count of items?

I'm using strapi and graphQL ,我正在使用stripigraphQL

with this query i can get posts通过这个查询,我可以得到帖子

query {
  
  posts{
    id,
    title
  }
}

i want to get posts and totalCount together ,desirable result would like this我想将帖子totalCount放在一起,理想的结果是这样的

{
  "data": {

"totalCount" : "3",
    "posts": [
      {
        "id": "1",
        "title": "first post "
      },
      {
        "id": "4",
        "title": "post two"
      },
      {
        "id": "5",
        "title": "post 3"
      }
    ]
  }
}

I've read document and I can make a query for getting just total count but it is not enough for me !我已经阅读了文档,我可以进行查询以获取总数,但这对我来说还不够! so , How can i get posts and totalCounts together ?那么,如何将帖子totalCounts放在一起?

I just found myself in your shoes right now and the solution I found was:我刚刚发现自己现在处于您的位置,我找到的解决方案是:

    query POSTS {
      postsConnection {
        aggregate {
          count
        }
      }
      posts{
        id
        title
      }
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM