graphql-python / graphql-python/graphene
PageInfo.hasPreviousPage is false on second page
- 主要言語
- Python
- スター
- 8.2k
- フォーク
- 818
- PR マージ指標
- 30日以内にマージされた PR はありません
説明
Hi guys,
I'm using `graphene==1.1.3` with `graphene-django==1.2.1`. I'm following the Relay specification and I'm having an issue with pagination on connections.
When paginating forward using the `first` and `after` arguments getting the first page is working fine but from the second page forward `hasPreviousPage` comes back `false`. For example, on a list of 20 users the `endCursor` for the first page of 5 items is `"abc5"`. If I ask for the second page of 5 items:
```javascript
query { users(first: 5, after: "abc5"){
pageInfo {hasPreviousPage hasNextPage startCursor endCursor}
}}
```
I get back:
```
{ "data": { "users": {
"pageInfo": {
"hasPreviousPage": false, <-- This should be true
"hasNextPage": true,
"startCursor": "abc6",
"endCursor": "abc10"
}
}}}
```
Same thing happens when paginating backwards but with `hasNextPage`. When I ask for the `...(last: 5, before: "abc16")` then `hasNextPage` comes back as `false`.
I think it's a bug on the `connection_from_list_slice` method in [this file](https://github.com/graphql-python/graphql-relay-py/blob/master/graphql_relay/connection/arrayconnection.py#L32). And here is a fragment of the code where I think the problem is:
```python
def connection_from_list_slice(list_slice, args=None, connection_type=None,
edge_type=None, pageinfo_type=None,
slice_start=0, list_length=0, list_slice_length=None):
# ...
first_edge_cursor = edges[0].cursor if edges else None
last_edge_cursor = edges[-1].cursor if edges else None
lower_bound = after_offset + 1 if after else 0
upper_bound = before_offset if before else list_length
return connection_type(
edges=edges,
page_info=pageinfo_type(
start_cursor=first_edge_cursor,
end_cursor=last_edge_cursor,
has_previous_page=isinstance(last, int) and start_offset > lower_bound,
has_next_page=isinstance(first, int) and end_offset < upper_bound
)
)
# ...
```
コントリビューションガイド
このリポジトリのコントリビューションガイドは索引されていません
調査の方向性
graphql_relay/connection/arrayconnection.py の connection_from_list_slice から始め、issue に記載されている前方向および後方向のページネーションのケースを比較します。後続のページで PageInfo が hasPreviousPage と hasNextPage を正しく報告することを、示されているカーソルの例を完了条件として検証します。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- graphql, python
- 領域
- api, backend
- issue の種類
- バグ
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 活発さ
- 停滞
- 明瞭さ
- 明確に書かれている
- 初心者へのやさしさ
- 50/100