I’m having a problem with my Query (working with ReactJS, mongoose, Apollo and Next). I want to have pagination with limit and skip (and fetchMore) but I also need to get the total amount of the Shop model. When I console.log(totalShops) it gets the total amount. But I don’t know how to access it in my code. Is there any way to get the number?
async shops(root, args) {
try {
// let totalShops = await Shop.count({})
return (shop = await Shop.find({})
.limit(args.limit)
.skip(args.skip)
.sort({ updatedAt: -1 })
)
} catch (err) {
throw new Error(err.message)
}
}
This is what my Schema looks like, I don’t know if that can help you.
shops(
limit: Int
skip: Int
): [Shop]
And using this in my page.
<Query query={GET_SHOPS} fetchPolicy="cache-and-network" variables={{ limit: this.state.limit, skip: this.state.skip }}>
{({ loading, error, data: { shops }, fetchMore }) => {
// components and other stuff
// I WANT TO ACCESS totalShops here somehow.
}}
</Query>
No responses yet.