graphql-spqr icon indicating copy to clipboard operation
graphql-spqr copied to clipboard

Aggregate syntax question

Open nolram88 opened this issue 6 years ago • 1 comments

I've been digging into how to implement aggregates for a single type in my project and here is an example I've found that seems pretty reasonable however I'm at a loss as to how to take the "fields" such as rating as an input for the "aggregate". Could I get a hint as to the approach for this?

  author (where: {id: {_eq: 1}}) {
    id
    name
    articles_aggregate {
      aggregate {
        count
        avg {
          rating
        }
        max {
          rating
        }
      }
      articles {
        id
        title
        rating
      }
    }
  }
}

nolram88 avatar Nov 26 '18 23:11 nolram88

Take a look at the way Prisma (https://www.prisma.io/) handles this.

TL;DR: Create fields such as rating_count, rating_avg, and rating_max, and treat them just like normal fields backed by resolver logic. GraphQL as a standard, and the tools built around it seem to want nothing to do with aggregation, I've found.

grrttedwards avatar Jan 22 '19 17:01 grrttedwards