如何将总计数传递给pageInfo中的客户端 [英] How to pass total count to the client in pageInfo

查看:167
本文介绍了如何将总计数传递给pageInfo中的客户端的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用first afterlast before进行分页. hasNextPagehasPreviousPage非常有用.

I use first after and last before to do pagination. hasNextPage and hasPreviousPage are very useful.

但是我还需要total count,这样我才能在客户端上计算并显示page 5 of 343 pages之类的东西.

But what I need is also the total count so that I can calculate and show things like page 5 of 343 pages on the client.

不幸的是,即使我在服务器站点上有此信息,它也不是pageInfo的一部分.

Unfortunately that is not part of pageInfo even though I have the information on the server site.

能否请您在pageInfo中包含一个total字段,并扩展connectionFromArray来像connectionFromArraySlice那样容纳全部arrayLength?

Can you please include a total field in the pageInfo and extend connectionFromArray to take in the total arrayLength like connectionFromArraySlice already does?

谢谢

推荐答案

pageInfo旨在表示有关特定页面的信息,而项的总数实际上是连接本身的属性.我们建议将count字段添加到连接中.您可以使用以下查询它:

pageInfo is designed to represent information about the specific page, whereas the total number of items is really a property of the connection itself. We recommend adding a count field to the connection. You might query it with:

fragment on TodoList {
  tasks(first: 10) {
    count # <-- total number of tasks
    edges { ... }
    pageInfo { ... }
}

中继在连接上支持任意字段,因此可以随意命名为counttotalCount等.

Relay supports arbitrary fields on a connection, so you're free to name this count, totalCount, etc.

这篇关于如何将总计数传递给pageInfo中的客户端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆