Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Adds the ability to fetch total post counts from WP-GraphQL

License

NotificationsYou must be signed in to change notification settings

builtbycactus/total-counts-for-wp-graphql

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 

Repository files navigation

As it stands WP-GraphQL doesn't implement thetotalCount field. This is due to a number of reasons, including the performance impact that would come with such a query.

We found that we needed this for a site being developed, so built up this basic plugin.

Whilst this doesn't implement thetotalCount field as per theGraphQL docs, it does add atotal field to thepageInfo 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.

Retrieving the total count.

To retrieve to total count, it's a simple case of requesting thetotal field with yourpageInfo. See below:

{posts(first:1){edges{node{idtitle}}pageInfo{totalhasNextPageendCursor}}}

This will then give you a result as such:

{"data": {"posts": {"edges": [        {"node": {"id":"cG9zdDozOA==","title":"Post B"          }        }      ],"pageInfo": {"total":2,"hasNextPage":true,"endCursor":"YXJyYXljb25uZWN0aW9uOjM4"      }    }  }}

As you can see, the total number of items is accessible viadata.posts.pageInfo.total.

Contributions

Contributions are welcome. This was a very quick build and as such there are probably performance gains to be had.

Feel free to make a PR against this repo!

About

Adds the ability to fetch total post counts from WP-GraphQL

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp