plugin-graphql
plugin-graphql copied to clipboard
Pagination
will this be supported soon?
Currently I have no plans, but PRs are welcome :)
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? :)
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!
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.
I'm going to have a need for this shortly. What would be involved in implementing this - just modifying the queryBuilder?
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.
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.
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
If someone does impliment this, please make generic to also support:
limit
and nextToken
- eg. AWS AppSync