0

I'm trying to make a pagination with mongose and graphql very similar to google (numeric type). But the results I have are not what I expected. The limit works and I think the offset also but I am trying to get the current page and the number of pages and it is not reaching me. I am using mongose pagginate v2 and in its doc it says that I can live all those values of the result.

-----Resolver Query----

const Product = require('../models/Product');

async function pagProducts(root, args){

console.log(args.page)
const query = Product.find({});
const options = {
page: args.page,
offset: args.offset, 
limit: args.limit,

}


await Product.paginate(query, options).then(function(result) {
console.log(result)/*Here I only get an array with the objects, the total of docs the limit and the offset but nothing of the current page and pages*/
})   
}

module.exports = {

  pagProducts
}

--------Schema.graphql

  type Product{
  _id: String
  title: String!
  price: Float
  unitydetail: String
  unityForPound: Int
 }

type Query {
pagProducts(offset: Int, limit: Int, page: Int):[Product]
}
user3821102
  • 139
  • 2
  • 13
  • See the [Examples](https://www.npmjs.com/package/mongoose-paginate#examples) in the documentation. Returns a result object with various properties. You are also handling the Promise incorrectly. – Neil Lunn Mar 08 '19 at 23:09
  • Hello Neil can you explain me a little better why you say my promise is wrong? I think I am passing the required arguments in the Documentation. Where I'm not sure is in my callback. Thanx – user3821102 Mar 08 '19 at 23:35
  • You can [edit] the post and add the details as to why it is different from the post marked as duplicate. – Bhargav Rao Mar 09 '19 at 00:06

0 Answers0