graphql-python / graphql-python/graphene

PageInfo.hasPreviousPage is false on second page

Abierto
#395 15 comentarios 8 reacciones 0 asignados Ver en GitHub
🐛 bug
Lenguaje dominante
Python
Estrellas
8.2k
Forks
818
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

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
)
)

# ...
```

Guía de contribución

No hay ninguna guía de contribución indexada para este repositorio

Línea de trabajo

Comienza en graphql_relay/connection/arrayconnection.py, en connection_from_list_slice, y compara los casos de paginación hacia delante y hacia atrás descritos en el issue. Verifica que PageInfo informe correctamente de hasPreviousPage y hasNextPage en las páginas posteriores, utilizando los ejemplos de cursores mostrados como criterio de finalización.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
graphql, python
Área
api, backend
Tipo de issue
Error
Dificultad
3/5
Tiempo estimado
1-2 días
Estado de actividad
Estancado
Claridad
Bien especificado
Aptitud para principiantes
50/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.