Count published articles via graphql

Hello,

I want to count the published articles via graphql but the query doesn’t work.

query countFilterArticles {
  articlesConnection(publicationState: LIVE) {
    aggregate {
      count
    }
  }
}

I also tried to use a where for this to get just the published articles:

query countFilterArticles {
  articlesConnection(where: { published_at_ne: null }) {
    aggregate {
      count
    }
  }
}

Both queries don’t work because it counts also the draft-article.

Thanks for some help with this!

Best regards,

Timo

I read something about Published-Connection at https://strapi.io/documentation/developer-docs/latest/plugins/graphql.html#aggregation-grouping but I think this is not working/available for me because we use postgres as database.

Is there a way to filter the published state in graphql?

Seems that the following query works:

query countFilterArticles {
  articlesConnection(where: { published_at_null: false }) {
    aggregate {
      count
    }
  }
}

Thanks for this code snippet. It helped me to solve my problem also.

Although I am facing another issue, maybe you can guide me in the right direction.

How can we count the articles of a specific category?

Let’s say I have four categories and I want to find how many articles are there in each category.

I’ll be very thankful to you for your help.