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

Pagination links #104

Closed
zamith opened this issue Apr 27, 2018 · 6 comments
Closed

Pagination links #104

zamith opened this issue Apr 27, 2018 · 6 comments
Assignees

Comments

@zamith
Copy link
Contributor

zamith commented Apr 27, 2018

As far as I could tell the QueryParser will correctly parse pagination data, but there is not way to then add pagination links (next, prev, first and/or last) to the links object at the collection level, as per the JSON:API spec.

Am I missing something or is it really a feature that is missing? If so, would you be willing to take a PR on that?

@zamith
Copy link
Contributor Author

zamith commented May 2, 2018

Created a PR for this #107.

@zamith
Copy link
Contributor Author

zamith commented Aug 30, 2018

Even though the PR is merged, there is still one outstanding issue with it. I'll paste what I wrote on the PR:

The issue here is that I need access to the pagination data on the links overridable function, so I can do something like this:

def links(data, conn, %{cursor: cursor}) do
  %{
    next: url_for_pagination(data, conn, %{cursor: cursor})
  }
end

Here it's being passed in the meta, if I try to pass it in the data like so:

render(conn, "index.json", %{data: %{collection: collection, pagination: pagination}})

Then the collection will be passed in on its entirety to the view, instead of being iterated over. That is because of this:

def encode_data(view, data, conn, query_includes) when is_list(data) do
  Enum.map_reduce(data, [], fn d, acc ->
    {to_include, encoded_data} = encode_data(view, d, conn, query_includes)
    {to_include, acc ++ [encoded_data]}
  end)
end

which will not be called, since data is not a list.

Does that make sense, or am I missing something?

@zamith
Copy link
Contributor Author

zamith commented Sep 12, 2018

I have the code ready for this, that I've been running, but wanted to get your take on it first. Please let me know how to proceed.

@doomspork
Copy link
Member

@zamith how about opening a PR? We can always close the PR if it's decided not to merge.

@jherdman
Copy link
Contributor

I believe this should be fully resolved now via #164 . I'm going to close this issue, @zamith . Feel free to reopen if you find the issue still unresolved.

@lucacorti
Copy link
Contributor

lucacorti commented Mar 15, 2019

Is this supposed to work? If so, how do you add pagination links?

I've enabled with_pagination in the config, but the responses don't include any links and I get in the logs:

[info] You've set with_pagination but have not defined any pagination links, thus no pagination links will be returned

I'm passing pagination parameters to Scrivener which returns a page/size/total data which I should pass back to the view somehow, but didn't find any hint in the docs on how to do this. The links callback from JSONAPI.View only processes the data, so I guess pagination links should not be manually generated there.

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

No branches or pull requests

6 participants