cult-of-coders / grapher

Grapher: Meteor Collection Joins + Reactive GraphQL like queries
https://atmospherejs.com/cultofcoders/grapher
MIT License
275 stars 53 forks source link

Allow $paginated queries to return the count along with the result #415

Open Floriferous opened 4 years ago

Floriferous commented 4 years ago

When you paginate a query, you usually want to know how many documents are left, or how many are available in total (when showing a pagination widget in a table for example).

To do this right now, the client needs to do 2 round-trips, and run the firewall twice, to get both info.

It would be interesting if the query could return the total count along with the results, for example:

  const cursor = Users.find(query, options);

  const results = cursor.fetch();

  if (options.limit) {
    const count = cursor.count();
    results._queryCount = count;
  }

  return results;

Maybe this is something that I could build in the meteor collections by default, instead of making grapher do this.