marshmallow-jsonapi icon indicating copy to clipboard operation
marshmallow-jsonapi copied to clipboard

Add support for pagination links

Open joe-pensa opened this issue 5 years ago • 6 comments

There does not appear to be any way to support pagination links (first, prev, next, last) as defined in the spec: https://jsonapi.org/format/#fetching-pagination

joe-pensa avatar Nov 27 '18 17:11 joe-pensa

I posted a workaround at https://github.com/marshmallow-code/marshmallow-jsonapi/issues/96#issuecomment-371975056, however, this should be implemented.

Requirements:

https://jsonapi.org/format/#fetching-pagination

  • To paginate the primary data, supply pagination links in the top-level links object. To paginate an included collection returned in a compound document, supply pagination links in the corresponding links object.
  • The page query parameter is reserved for pagination. Servers and clients SHOULD use this key for pagination operations.
  • The following keys MUST be used for pagination links:
    • first: the first page of data
    • last: the last page of data
    • prev: the previous page of data
    • next: the next page of data
  • JSON:API is agnostic about the pagination strategy used by a server.

@sloria Design and implementation:

  1. Schema().dump(items, paginate=True) or Schema().paginate_dump(items)?
  2. How should the pagination data: first, last, etc be passed for dumping?
  3. General Schema and flask.Schema support (flask-sqlalchemy pagination object).

scottwernervt avatar Nov 28 '18 18:11 scottwernervt

thank you.

joe-pensa avatar Nov 28 '18 18:11 joe-pensa

Hello, Correct if i'm wrong. But adding this functionality to the dump method would also add pagination links to the flask-marshmallow jsonify. I need this and currently i'm doing a work around using the paginate object of the flask-sqlalchemy. If thats the case i can take this issue. Or would be better to create one in the flask-marshmallow project?

joaozeni avatar Nov 18 '19 15:11 joaozeni

It will only add pagination links if you're using marshmallow-jsonapi.Schema as the base for your schemas, rather than flask_marshmallow.Schema

multimeric avatar Nov 18 '19 21:11 multimeric

OK, cool. So i will open an issue in the flask-marshmallow project. I guess the solutions will be some what similar, so if i can i will take this one after.

joaozeni avatar Nov 19 '19 00:11 joaozeni

How do I use this workaround in Flask? There are two variables that are undefined in the code sample: ujson and dasherize. Should they be imported from somewhere? It'd be good to include an example on how to invoke the class as well.

lljr avatar Nov 13 '20 21:11 lljr