plugin-graphql icon indicating copy to clipboard operation
plugin-graphql copied to clipboard

Pagination

Open tonipepperoni opened this issue 6 years ago • 9 comments

will this be supported soon?

tonipepperoni avatar Jun 24 '18 17:06 tonipepperoni

Currently I have no plans, but PRs are welcome :)

phortx avatar Jun 25 '18 06:06 phortx

How would you like to have the pagination? As fetch params?

User.fetch({ id: 42 }, { perPage: 8, page: 2}) would be my suggestion. What do you think? :)

phortx avatar Jun 27 '18 13:06 phortx

something like that would be cool. i think it would need to return: total, perPage, page, lastPage and have different pagination modes depending on type of connection.

I'll see what i can come up with!

tonipepperoni avatar Jun 28 '18 14:06 tonipepperoni

Thanks for your answer :)

and have different pagination modes depending on type of connection.

Could you specify what this means?

something like that would be cool. i think it would need to return: total, perPage, page, lastPage

I'm thinking about how we could give that meta information to the developer. Currently the fetch action returns a object with the fetched data. We could change that so that fetch returns an object with meta information. I could think about:

  • total records fetched
  • records perPage
  • current page
  • lastPage
  • query time
  • list of fetched records (what fetch returned before)
const meta = await User.fetch(null, { perPage: 8, page: 2}); // null means no filterting
console.log(meta);
{
  records: 7,
  perPage: 8,
  currentPage: 2,
  lastPage: 2,
  queryTime: 86, // ms
  records: {
    users: [ ... ],
    profiles: [ ... ]
  }
}

We could add more information in the future. For consistency I think the other actions should also return this meta object despite there will be no page information.

phortx avatar Jun 29 '18 07:06 phortx

I'm going to have a need for this shortly. What would be involved in implementing this - just modifying the queryBuilder?

colinfindlay-nz avatar Aug 08 '18 06:08 colinfindlay-nz

Probably. I didn't looked at pagination in depth, so I can't tell currently.

Also I'm really busy currently and can't implement this.

First step would be to introduce pagination in the test schema and setup some specs so implement against.

Then I think the fetch.ts and maybe the vuex actions have to be modified. After that the queryBuilder.ts and maybe the transformer.ts has to be modified.

phortx avatar Aug 08 '18 06:08 phortx

I'll have a look and see if we can fit this into our schedule. I also need to be able to return arbitrary data attached to edges - so not sure if this would be a natural extension. Or something we just implement internally.

colinfindlay-nz avatar Aug 08 '18 07:08 colinfindlay-nz

Fetching of arbitrary data could be possible via model unrelated custom queries: https://vuex-orm.github.io/vuex-orm-graphql/guide/custom-queries/#model-unrelated-simple-query

phortx avatar Aug 08 '18 07:08 phortx

If someone does impliment this, please make generic to also support:

limit and nextToken - eg. AWS AppSync

ranguard avatar May 02 '19 13:05 ranguard