Graphql-ruby: Implementing simple prev/next pagination

Created on 19 Jul 2017  路  9Comments  路  Source: rmosolgo/graphql-ruby

Hello,

i've seen few issues about it here but none of them are an answer for my question. I need to implement a simple Previous / Next pagination (without page numbers etc) but i'm not able to use pageInfo.hasPreviousPage and pageInfo.hasNextPage in cause of a thing mentioned in here: https://github.com/rmosolgo/graphql-ruby/issues/656 (long story short - when paginating forwards with first, hasPreviousPage always returns false - which doesn't let me use it to check if there is a previous page available or not).

The only way of doing it with my current knowledge is to implement the check on frontend side (check if user ever clicked the Next page button, store all the cursors and do all the Previous button logic on the frontend side). But that solution sucks a bit, i would definitely prefer that info to be extractable from the graphql rather than storing it on frontend side.

Is there currently any way of doing it? Any dirty hacks are also welcome :) Thanks!

Most helpful comment

I'm all for making it opt-in. Unfortunately my monkey patch won't help the community at large because we're on graphql-pro. I'll circle back and see if I can take a stab at a PR on the public version if anyone else hasn't gotten to it.

All 9 comments

My team just ran up against this issue as well. I'm trying to work something out on our app, if I come to a solution I'll report it back here.

same here

We just recently fixed this in GitHub... but all our connections are custom, so it was fixed at that level 馃槵

I'm convinced that departing from the Relay spec is good here, but I would like to make it opt-in, since it results in more DB queries.

I'm all for making it opt-in. Unfortunately my monkey patch won't help the community at large because we're on graphql-pro. I'll circle back and see if I can take a stab at a PR on the public version if anyone else hasn't gotten to it.

Did this get resolved. Its a pretty basic functionality you would expect to work...

I believe this has been resolved with the bidirectional_pagination attr on connections https://github.com/rmosolgo/graphql-ruby/search?q=bidirectional&unscoped_q=bidirectional

@thebadmonkeydev how would I implement it in an endpoint like this

field :users, Types::User.connection_type, null: false do
end

def users
    User.all
end

I put it in the schema file, seems to work, thanks 馃尞

Hi, I'm helping to close out old issues. From the discussion, it seems that this issue has been resolved.

I'm closing it, let me know if you'd like to reopen it.

Was this page helpful?
0 / 5 - 0 ratings