-
Notifications
You must be signed in to change notification settings - Fork 860
Grouping and Aggregation #70
Comments
May we get sum aggregate functionality. I need to use |
The schema I proposed in my original post does not make that much sense. Main issue: We will have to issue the command that indicates aggregation above the model that is aggregated in the AST. Let's consider again the model mentioned above:
A possible solution could look like this: Aggregating by one field at top level
Basic concept:
The result might look like this:
Aggregating by two fields at top level
The result might look like this:
Aggregating by one field at lower level
Nested aggregation
Further considerations
|
Since we're using a nice tree-based data format, we are not forced to aggregate over relations if we don't want to.
Could return something like
Formally, that would be the same as aggregating the exams by joining them in a list. |
I read the suggestion on aggregations, I think a standard 'aggregations' field on every Type is a lot easier to work with that all those type-name-specific fields mentioned above:
The aggregations can not be mixed with 'normal fields', but could be nested:
Also note the use of groupby, that is indeed a powerful combination with aggregation. |
I'm also looking for this feature |
Looking forward to this feature |
Pretty big blocker for me now, as this task is pretty heavy for the client. query showtimesTodayByCinemas {
allMovies(
groupBy: {
showtimes { cinema { id } }
}
) {
title
showtimes {
playingAt
}
}
} I dont know about this {
"allMovies": [{
"cinema": {
"id": "..."
},
"groupBy": [{ // <-- would this be correct name from aggregation?
"title": "The Hitman's Bodyguard",
"showtimes": [{ "..." }]
}]
}]
} |
+1 |
Highly needed, +1 |
+1 |
Is there any plan to do this feature anytime soon ? Also all those propositions of API are great but I just have one concern about the returned data. Do the clients like apollo handle this kind of data and know how to inspect the results or they just rely on object and array and in this case the group_by will just be a property of the object. If they don't handle that maybe one solution could be to do as many filter as needed and group everything into a batch query (this may seems really too much but I'm not not sure the group_by is something that graphql can manage easily) Also, why not user the If we don't take the group_by but use multiple query we would have something like that
This can easily be done by a script to generate all the queries and like that we just get some normal data and not nested that maybe (and it's a big maybe because I don't know) apollo and other client don't support. If so we could add the group by but I still think we should use the Would be happy to hear any feedback. This feature is quite important for me, at least the aggregation, there is still the multi query workaround for the groupby so if this feature is not in the roadmap, I will be happy to try to implement it on the backend but it could be good to have a good API first |
Is there a hack solution to this? I'm assuming the only way to do this is to create a custom function? |
@antho1404 This item is fairly high on our roadmap. I would encourage everybody to experiment with the API design so we can have a broader discussion before implementation starts. I like the general approach in this proposal, but it has limitations as highlighted in several comments, so we might end up with a final design that is significantly different. Feel free to contribute more ideas and feature requests :-) |
@sorenbs Is it possible to update the opening post with the lessons learned from the comments and the current proposal? |
Thank you all for the discussion here. It has been very enlightening. GraphQL turns out to be a very nice language to retrieve aggregated data. I have created a final proposal taking into account all points raised here: #1312 |
It would be awesome to support native grouping and aggregation within graphcool.
This foldable block contains an outdated proposal. Pleas see below for the new one
Given the following schema:
I would like to propose to add the following pseudo-schema, like you did for the filter API.
Note that the above solution only groups by one field. Technically, it is possible to group by a list of fields. I don't see how this could be done nicely in GraphQL, except maybe passing a list of fields to the
groupby
function.This issue might overlap with #56 for some use cases. Grouping is also mentioned in #40.
The text was updated successfully, but these errors were encountered: