Reputation:
async function find(ctx) {
return await strapi.services.article.find(ctx.query)
}
This is my controller
resolver: async (obj, options, ctx) => {
const result = await strapi.query('active').model.find({ article_id: obj.id});
return result.length > 0;
}
This is my resolver
I have this on my strapi backend and I am trying to figure out how to do pagination. Because there are so many ways to go about it and it's not documented very well, I am not sure what we can do. Is this using Mongoose and also, how do you send the data from the controller to the resolver exactly?
resolver: async (obj, options, ctx) => {
const result = await strapi.query('active').model.find({ article_id: obj.id}).limit(obj.limit).offset(obj.offset);
return result.length > 0;
}
Is it possible to do this since I am assuming it is mongoose that's being used? If not, how can we change the resolver to paginate the articles?
Upvotes: 0
Views: 4080
Reputation: 1140
for strapi v3, you can use something like this:
const result = await strapi.query("model").find({
id: id,
_start: page > 0 ? (page - 1) * pageSize : 0,
_limit: pageSize,
_sort: "created_at:desc",
});
Upvotes: 0
Reputation: 329
It is possible to use the Query Engine API that has build in pagination:
strapi.db.query('api::article.article').findMany({
offset: 15,
limit: 10,
});
Upvotes: 0