{"id":13516220,"url":"https://github.com/builtbycactus/total-counts-for-wp-graphql","last_synced_at":"2025-03-31T06:30:26.549Z","repository":{"id":220226281,"uuid":"203570717","full_name":"builtbycactus/total-counts-for-wp-graphql","owner":"builtbycactus","description":"Adds the ability to fetch total post counts from WP-GraphQL","archived":false,"fork":false,"pushed_at":"2022-08-31T16:29:17.000Z","size":12,"stargazers_count":18,"open_issues_count":2,"forks_count":5,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-11-01T20:36:19.123Z","etag":null,"topics":["wordpress","wordpress-plugin","wp-graphql"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/builtbycactus.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-08-21T11:32:09.000Z","updated_at":"2024-09-21T03:58:04.000Z","dependencies_parsed_at":null,"dependency_job_id":"01e240e5-122d-4241-bb63-01092e85384b","html_url":"https://github.com/builtbycactus/total-counts-for-wp-graphql","commit_stats":null,"previous_names":["builtbycactus/total-counts-for-wp-graphql"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/builtbycactus%2Ftotal-counts-for-wp-graphql","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/builtbycactus%2Ftotal-counts-for-wp-graphql/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/builtbycactus%2Ftotal-counts-for-wp-graphql/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/builtbycactus%2Ftotal-counts-for-wp-graphql/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/builtbycactus","download_url":"https://codeload.github.com/builtbycactus/total-counts-for-wp-graphql/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246429459,"owners_count":20775805,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["wordpress","wordpress-plugin","wp-graphql"],"created_at":"2024-08-01T05:01:20.441Z","updated_at":"2025-03-31T06:30:26.543Z","avatar_url":"https://github.com/builtbycactus.png","language":"PHP","funding_links":[],"categories":["Plugins"],"sub_categories":["WordPress"],"readme":"# Total Counts for WP-GraphQL\n\nAs it stands WP-GraphQL doesn't implement the `totalCount` field. This is due to a number of reasons, including the performance impact that would come with such a query.\n\nWe found that we needed this for a site being developed, so built up this basic plugin.\n\nWhilst this doesn't implement the `totalCount` field as per the [GraphQL docs](https://graphql.org/learn/pagination/#end-of-list-counts-and-connections), it does add a `total` field to the `pageInfo` object that is used for pagination. This seemed like the most sensible place to put it, as 99% of the time, we'll be using this field to pull back the total number of items, alongside our paginated result.\n\n\n\n## Retrieving the total count.\n\nTo retrieve to total count, it's a simple case of requesting the `total` field with your `pageInfo`. See below:\n\n```js\n{\n  posts(first:1) {\n    edges {\n      node {\n        id\n        title\n      }\n    }\n    pageInfo {\n      total\n      hasNextPage\n      endCursor\n    }\n  }\n}\n```\n\nThis will then give you a result as such:\n\n```json\n{\n  \"data\": {\n    \"posts\": {\n      \"edges\": [\n        {\n          \"node\": {\n            \"id\": \"cG9zdDozOA==\",\n            \"title\": \"Post B\"\n          }\n        }\n      ],\n      \"pageInfo\": {\n        \"total\": 2,\n        \"hasNextPage\": true,\n        \"endCursor\": \"YXJyYXljb25uZWN0aW9uOjM4\"\n      }\n    }\n  }\n}\n```\n\n\n\nAs you can see, the total number of items is accessible via `data.posts.pageInfo.total`.\n\n\n\n## Contributions\n\nContributions are welcome. This was a very quick build and as such there are probably performance gains to be had.\n\nFeel free to make a PR against this repo!","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbuiltbycactus%2Ftotal-counts-for-wp-graphql","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbuiltbycactus%2Ftotal-counts-for-wp-graphql","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbuiltbycactus%2Ftotal-counts-for-wp-graphql/lists"}