-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
[Relay] Pagination bug about previous/next #656
Comments
Can you help me understand the problem? It looks like some people requested a change to the Relay spec, but nobody has changed the spec yet. Is that right? |
@rmosolgo This makes me strange, the spec still incorrect after more than a year the bug found. Although there is a issue #103 about this change request, and there should be a PR for that according:
But I can‘t found the PR yet. |
It looks like the PR for the bug in the spec was never opened. It'd be nice of graphql-ruby could fix this in anticipation of the spec being corrected. |
Note that I quickly worked around this by monkey-patching GraphQL::Relay::BaseConnection, ArrayConnection, RelationConnection so that the methods has_next_page and has_previous page do not check the first and last arguments respectively. e.g., in BaseConnection:
|
@blevine I tried this patching, than server side works good. |
That's unfortunate. I hadn't tried this with an actual Relay client yet. What request were you making and what was the specific error you received? |
@blevine
Graphql Server respond correct: {
data {
viewer {
articles {
edges {
...
}
pageInfo {
hasNextPage: true
hasPreviousPage: true
}
}
}
}
} But I debug in react component to found |
Also here is my flawed solution for react-relay: render() {
const { edges, pageInfo } = this.props.viewer.articles;
const hasPreviousPage = pageInfo.startCursor !== 'MQ==';
const hasNextPage = pageInfo.startCursor === 'MQ==' || edges.length === pageSize;
return (
<Pagination
goToNextPage={this.goToNextPage}
goToPrevPage={this.goToPrevPage}
hasNextPage={hasNextPage}
hasPreviousPage={hasPreviousPage}
/>
);
} |
It sounds like this is spec-compliant, right? I'd be happy to support behavior this behavior but only if:
Feel free to reopen this when one of those happens! |
@blevine (or anyone) - could you share the exact monkey-patched code you used to make it work? I'm not good at monkey patching and all my attempts are failing so obviously i'm doing something wrong, it would be really handy to see a full code sample here :) Edit: Ok, i assume it's not a proper solution as, in my case, |
@mbajur Here is simple patch if you use rails: Create
|
Unfortunatelly @Xuhao - your code makes my API forces me to use both |
@mbajur So you just test your API directly(via curl or graphiQL) ,but without any graphql client(like relay) right? |
Yeah, exactly, i'm using graphiql for it |
@mbajur strange, it tried this patch before and was worked. Maybe new version made some changes on it. |
Out of curiosity - are you using both |
In my case, last is nil. Strange |
According to this reply, there is a bug in Relay Cursor Connections Specification
And the implementation here:
graphql-ruby/lib/graphql/relay/relation_connection.rb
Lines 19 to 25 in 756373a
So:
pageInfo.hasPreviousPage is always false when paging forwards, pageInfo.hasNextPage is always false when paging backwards
My env:
server side:
graphql (1.5.5)
client side:
react-relay@^0.10.0
My query to support pagination:
when clicking next:
when clicking previous:
The text was updated successfully, but these errors were encountered: