-
Notifications
You must be signed in to change notification settings - Fork 828
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PageInfo.hasPreviousPage is false on second page #395
Comments
I'm seeing the same issue as well even when not using the graphene-django plugin. |
I have this problem as well. According to the spec it seems like this is expected behavior but for the life of me I can't understand why. |
I'm closing the issue here, as is more related on the spec than this implementation. |
Hi @syrusakbary, coud you please reopen this issue because the spec changed on 12 Sep 2017? |
Hi @daironmichel . We're currently going through old issues that appear to have gone stale (ie. not updated in about the last 3 months) to try and clean up the issue tracker. If this is still important to you please comment and we'll re-open this. Thanks! |
Hi, I'd like to keep this issue open if you don't mind. |
Though I find this fairly annoying, I do understand why the Relay spec allows this - it can apparently reduce server load, and the client doesn't need the server to tell it the missing info. When you're paginating, the client knows there is a previous page if you just clicked "next"; you must have clicked "next" from somewhere. Implementation details:
Here's a concrete example, using Vue and Vue-Apollo: export default {
apollo: {
myQuery: {
query: gql`
query myPaginatedQuery(
$first: Int
$last: Int
$after: String
$before: String
) {
myQuery(
first: $first
after: $after
last: $last
before: $before
) {
edges {
node {
uuid
name
}
}
pageInfo {
hasNextPage
hasPreviousPage
startCursor
endCursor
}
}
}
`,
variables() {
return {
first: this.itemsPerPage,
after: null,
};
},
},
},
data() {
return {
itemsPerPage: 10,
hasNextPage: null,
hasPrevPage: null,
};
},
computed: {
// use these to determine whether there is actually a previous or next page
canNextPage() {
if (this.hasNextPage !== null) {
return this.hasNextPage;
} else if (this.myQuery) {
return this.myQuery.pageInfo.hasNextPage;
} else {
return false;
}
},
canPrevPage() {
if (this.hasPrevPage !== null) {
return this.hasPrevPage;
} else if (this.myQuery) {
return this.myQuery.pageInfo.hasPreviousPage;
} else {
return false;
}
},
},
methods: {
async showMore(previous = false) {
await this.$apollo.queries.myQuery.fetchMore({
variables: previous
? {
last: this.itemsPerPage,
before: this.combatantSet.pageInfo.startCursor,
}
: {
first: this.itemsPerPage,
after: this.combatantSet.pageInfo.endCursor,
},
updateQuery: (priorResult, { fetchMoreResult }) => fetchMoreResult,
});
if (previous) {
this.hasPrevPage = null;
this.hasNextPage = true;
} else {
this.hasPrevPage = true;
this.hasNextPage = null;
}
},
},
}; |
@jkimbo Can you keep this open? I don't believe this is fixed. |
I'm also a little flummoxed. The spec reads:
In this instance, after is set and there's really no reason the server can't efficiently determine that a prior page exists. At the very least, it should be an option on one's Connection class to spend the extra few cycles to look backwards in the index. I think for a lot of purposes, it would make sense for hasPreviousPage to report on whether the server has a previous page, and to my reading of the spec, while that's not required, it is allowed. |
I have this problem as well. Is there any workaround or solution to this issue yet? |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
I think this works as intended and is not a bug (the naming is just unclear); the idea is that the server can efficiently determine if there's a previous page. Efficient in this sense apparently means 'without executing additional queries' and 'without maintaining state'. So in that sense For instance, iterating through
If there's gaps in the list, e.g.
By maintaining state in the frontend as suggested above, you can avoid relying on solely on what the backend is reporting. I agree that it's counterintuitive, though :-) |
Hi guys,
I'm using
graphene==1.1.3
withgraphene-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
andafter
arguments getting the first page is working fine but from the second page forwardhasPreviousPage
comes backfalse
. For example, on a list of 20 users theendCursor
for the first page of 5 items is"abc5"
. If I ask for the second page of 5 items:I get back:
Same thing happens when paginating backwards but with
hasNextPage
. When I ask for the...(last: 5, before: "abc16")
thenhasNextPage
comes back asfalse
.I think it's a bug on the
connection_from_list_slice
method in this file. And here is a fragment of the code where I think the problem is:The text was updated successfully, but these errors were encountered: