Do you guys know when other query aggregations wil...
# orm-help
j
Do you guys know when other query aggregations will come in prisma? I need to have like an AVG of all the rates a topic has and show it and wanted to do it from the server without using resource on the client to calculate it since i'm working on a mobile app. Was messing around and thought on something like this
Copy code
getUserRateAverage(parent, args, ctx, info) { 
    let rates = ctx.db.query.rates({}, info);
    let sum = 0;
    for (let i = 0; i < rates.length; i++) {
      sum += rates[i];
    }

    return rates.length != null ? sum / rates.length : 0;
  },
but don't know if this is even legit hahahaha, really new with GraphQL and Prisma. Let me know!
n
you can track this feature request for more aggregation functions: https://github.com/prisma/prisma/issues/1312
j
@nilan Thanks for the reply. Going to read that feature request right now. Waiting so that will be implemented is that short snippet i shared fine for the issue i'm having or you would do it in another way?
n
seems good to me, however you don't need to pass in
info
I guess
j
@nilan Thanks again for the reply. Another questions i was thinking. So I retrieve all topics like this
Copy code
query{
 getTopics{
   title
}
}
, is it possible to attach to it the topicAverage for example? Right now I'm calling it with the snippet passing a topicID and calculating all the rates but If I could do it with one request instead of fetching all the topics and after that fetching for each post the average, that would be super useful. Accessing it like this maybe
Copy code
getTopics{
 title,
 rateAVG
}