<p>Try <code>entryCount</code>. You can also add arguments to this, such as <code>section</code>: <code>entryCount(section:"news")</code>, for example.</p>

CC BY-SA 4.0
2020-06-18T15:32:12.610Z
Thanks, but:
There doesn't seem to be such option in what i'm trying. Can you elaborate how you've done this?
All i get is "cannot query "entryCount" on query" or "cannot query "entryCount" on type elementInterface"
Or i just don't know where to put the "entryCount", also possible!
Vincent
CC BY-SA 4.0
2020-09-07T10:19:06.070Z
Fastforward however much time has passed.
Looking back at graphql in the current version of Craft (3.5.8) and 'entryCount' works fully as expected. I haven't looked into the changelog, but I'm assuming it has been added somewheren between then and now! 
Marking your answer as accepted for if anybody is looking for it.
Vincent
CC BY-SA 4.0
2020-06-14T23:37:53.993Z
2020-06-14T23:37:53.993Z
Chris Clower
<p>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.</p>

<p>I'm doing a query like this:</p>

<pre><code>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,
    }
  }
}
</code></pre>

<p><em>Truncated for readability</em></p>

<p>I set a limit and an offset to see the first 10 results.
But i also need to know <em>the total amount</em> to determine how many pages there are</p>

<p>I've seen that there is a <code>_count</code> field of type <code>Int</code> on the <code>entryInterface</code> 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:</p>

<pre><code>query($search: String, $relatedTo: [Int]) {
  entries(section: "address", search: $search, ... same) {
    _count:id,
  }
}
</code></pre>

<p>It just adds in the response <code>{"_count": "8154"}</code> (which is the id, so not very usefull)</p>

<p>I've looked at graphql docs:
<a href="https://graphql.org/learn/pagination/" rel="nofollow noreferrer">https://graphql.org/learn/pagination/</a></p>

<p>But it doesn't work to just add 'pageInfo' or 'totalCount', neither does the cursor stuff.</p>

<p>Any help to get this working is welcome!</p>

<craft3><search><pagination><graphql>
Graphql total results / pageinfo when searching with pagination
# Graphql total results / pageinfo when searching with pagination

(Asked by: username_0 on 2020-05-04)

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!

**Tags:** craft3, search, pagination, graphql


---

## 1 answers

### Answer by username_1 on 2020-06-14. Score: 3 | Accepted answer

Try `entryCount`. You can also add arguments to this, such as `section`: `entryCount(section:"news")`, for example.

> **Comments:**
> **username_0**: Thanks, but: There doesn't seem to be such option in what i'm trying. Can you elaborate how you've done this? All i get is "cannot query "entryCount" on query" or "cannot query "entryCount" on type elementInterface" Or i just don't know where to put the "entryCount", also possible!  
> **username_0**: Fastforward however much time has passed. Looking back at graphql in the current version of Craft (3.5.8) and 'entryCount' works fully as expected. I haven't looked into the changelog, but I'm assuming it has been added somewheren between then and now!  Marking your answer as accepted for if anybody is looking for it.  

---

