GraphQL Aggregation Directives #4870
PascalSenn
started this conversation in
Feature Request
Replies: 3 comments
-
Moreover, what is the Thirdly, we should have the |
Beta Was this translation helpful? Give feedback.
0 replies
-
I will do a more thorough review tonight. |
Beta Was this translation helpful? Give feedback.
0 replies
-
Took this over from lodash, agree we should do @unique
This is indeed a bug of the documentation |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
We are currently working on a new data aggregation feature for server and client. (#4068 )
The idea for the aggregation directives was inspired by graphql-lodash
The difference between graphql loadash and this implementation, is that we want to remove the javascript semantics from the implementation. GraphQL Lodash simply maps the lodash functions into directives. This means that you can also receive
[object Object]
and other JS specific responses.The implementation we do, follows a specification. All aggregations have a specific algorithm that they follow and test cases that an implementation must pass to be valid.
The aggregations are defined on a GraphQL Query, but are executed on json documents. They are not bound to the type system or the types of fields.
A major difference between graphql-lodash and this implementation is, that there is not just one directive with arguments per operation, but a directive per operation with N arguments.
This adds more flexibility in evolving the directives further.
You can checkout the specification here: https://pascalsenn.github.io
Stitching
These directives maybe be used in the future to simplify type extensions and schema rewrites in stitching
Discussion
map
countBy
is just a string. It could also be aPath
. so that you could select fields deeper in the treeCurrently this can be done with multiple map declarations:
with the
Path
scalar it could be done like this:@uniq
can be applied on a list of scalar values and returned a duplicate free list.@uniqBy(key: "foo")
can be applied on a list of objects, and returns a list of objects that are distinct by the value of the fieldkey
At the moment we also have
maxBy
,minBy
,meanBy
,sumBy
.To be consistent we would also have to create
max
,min
,mean
,sum
.Alternatively we could combine these pairs of directives into one by making the
key
attribute optional.instead of
we could do
@drop
and@dropRight
to@skip
and@skipRight
. (as we also have@take
and@takeRight
)Right
part of@takeRight
and@dropRight
/@skipRight
toEnd
,Last
or similar?Product
Hot Chocolate
Beta Was this translation helpful? Give feedback.
All reactions