I'm trying to build something to search my data that is stored in Craft with graphql. To make pagination work I want to know how many results there are in total.
I'm doing a query like this:
query($search: String, $relatedTo: [Int]) {
entries(section: "address", search: $search, orderBy: "companyName", relatedTo: $relatedTo, limit: 10, offset: 0) {
searchScore,
... on address_address_Entry {
sid,
address_title,
}
}
}
Truncated for readability
I set a limit and an offset to see the first 10 results. But i also need to know the total amount to determine how many pages there are
I've seen that there is a _count
field of type Int
on the entryInterface
which says "Return a number of related elements for a field." But it seems to just give me the field's value itself, if I, for example, add it like this:
query($search: String, $relatedTo: [Int]) {
entries(section: "address", search: $search, ... same) {
_count:id,
}
}
It just adds in the response {"_count": "8154"}
(which is the id, so not very usefull)
I've looked at graphql docs: https://graphql.org/learn/pagination/
But it doesn't work to just add 'pageInfo' or 'totalCount', neither does the cursor stuff.
Any help to get this working is welcome!