How to paginate with DatoCMS GraphQL API? (total page count, end of results)

I’ve read the DatoCMS docs on GraphQL pagination (https://www.datocms.com/docs/content-delivery-api/pagination) which explains the first (page size) and skip (page offset) properties.

But, how would one render full pagination controls? Such as:

I haven’t paginated with GraphQL before. Reading their docs (https://graphql.org/learn/pagination/), they recommend additional API properties. That’s what I’m used to on traditional REST API endpoints too: some sort of totalCount property so I can calculate how many pages to expect, and whether a “next” page is available.

But I’m looking through the DatoCMS docs and the API explorer, and not seeing similar properties (totalCount, cursor, hasNextPage, etc).

Is there a way to render client pagination controls with DatoCMS GraphQL?

hello @alex.burner right, I’m going to amend the documentation right now, we haven’t mentioned there that you can query the meta object like this:

_allYourModelMeta {
  count
}

to get the total count of the records, that should solve your problem, right?

Yes, perfect! Thank you, that’s the missing piece to make this all work

1 Like