Skip to content
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

Incosistency on Connection.offset/1 #106

Open
ggcampinho opened this issue Feb 22, 2018 · 0 comments
Open

Incosistency on Connection.offset/1 #106

ggcampinho opened this issue Feb 22, 2018 · 0 comments

Comments

@ggcampinho
Copy link

ggcampinho commented Feb 22, 2018

Current behavior

When the pagination is :forward the offset is changed, but when the pagination is :backward the offset remains the same of the request. Ex:

iex(2)> Connection.offset(%{first: 2, after: Connection.offset_to_cursor(2)})
3
iex(3)> forward_args = %{first: 2, after: Connection.offset_to_cursor(2)}
%{after: "YXJyYXljb25uZWN0aW9uOjI=", first: 2}
iex(4)> Connection.offset(forward_args)
3
iex(5)> Connection.limit(forward_args) 
{:ok, :forward, 2}
iex(6)> backward_args = %{last: 2, before: Connection.offset_to_cursor(2)}
%{before: "YXJyYXljb25uZWN0aW9uOjI=", last: 2}
iex(7)> Connection.offset(backward_args)                                  
2
iex(8)> Connection.limit(backward_args) 
{:ok, :backward, 2}

Expected behavior

iex(2)> Connection.offset(%{first: 2, after: Connection.offset_to_cursor(2)})
3
iex(3)> forward_args = %{first: 2, after: Connection.offset_to_cursor(2)}
%{after: "YXJyYXljb25uZWN0aW9uOjI=", first: 2}
iex(4)> Connection.offset(forward_args)
3
iex(5)> Connection.limit(forward_args) 
{:ok, :forward, 2}
iex(6)> backward_args = %{last: 2, before: Connection.offset_to_cursor(2)}
%{before: "YXJyYXljb25uZWN0aW9uOjI=", last: 2}
iex(7)> Connection.offset(backward_args)                                  
0
iex(8)> Connection.limit(backward_args) 
{:ok, :backward, 2}

Internally the calculation actually happens at https://github.com/absinthe-graphql/absinthe_relay/blob/master/lib/absinthe/relay/connection.ex#L279, but it seems to me that the method is behaving differently depending on the direction and would be easier if it returns the proper offset for the query.

The documentation on the method also explains that this is the expected behavior, I can submit a PR if that makes sense

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant