简体   繁体   中英

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

I'm using strapi and graphQL ,

with this query i can get posts

query {
  
  posts{
    id,
    title
  }
}

i want to get posts and totalCount together ,desirable result would like this

{
  "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 ?

I just found myself in your shoes right now and the solution I found was:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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