Chr*_*ine 8 javascript reactjs graphql-js relayjs
我使用first after和last before做分页.
hasNextPage并且hasPreviousPage非常有用.
但我需要的是total count,我可以计算和显示page 5 of 343 pages客户端上的内容.
不幸的是,pageInfo即使我在服务器站点上有信息,这也不是其中的一部分.
能否请您包括total在该领域pageInfo,并延伸connectionFromArray至采取在总arrayLength像connectionFromArraySlice已经这样做?
谢谢
Joe*_*ona 12
pageInfo旨在表示有关特定页面的信息,而项目总数实际上是连接本身的属性.我们建议count在连接中添加一个字段.您可以使用以下命令查询:
fragment on TodoList {
tasks(first: 10) {
count # <-- total number of tasks
edges { ... }
pageInfo { ... }
}
Run Code Online (Sandbox Code Playgroud)
继电器支持一个连接上的任意字段,所以您可以自由命名此count,totalCount等等.
谢谢@Joe Savona
他是绝对正确的.因为我花了一点时间弄清楚如何将属性实际添加到服务器站点上的连接,我想我也在这里分享:
var {connectionType: postsConnection} = connectionDefinitions({
name: 'post',
nodeType: qlPost,
connectionFields: () => ({
totalCount: {
type: GraphQLInt,
resolve: (connection) => connection.totalCount,
description: `A count of the total number of objects in this connection, ignoring pagination.
This allows a client to fetch the first five objects by passing "5" as the
argument to "first", then fetch the total count so it could display "5 of 83",
for example.`
}
})
});
Run Code Online (Sandbox Code Playgroud)
希望能帮助别人.
干杯
| 归档时间: |
|
| 查看次数: |
2656 次 |
| 最近记录: |