簡體   English   中英

Strapi & graphql:如何獲得項目總數?

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

我正在使用stripigraphQL

通過這個查詢,我可以得到帖子

query {
  
  posts{
    id,
    title
  }
}

我想將帖子totalCount放在一起,理想的結果是這樣的

{
  "data": {

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

我已經閱讀了文檔,我可以進行查詢以獲取總數,但這對我來說還不夠! 那么,如何將帖子totalCounts放在一起?

我剛剛發現自己現在處於您的位置,我找到的解決方案是:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM