Hello, I am building a graphql api on the top of neo4j. My model looks like following:
Now, when listing all orders for my downline (clients up to N levels below me)
I end up with the following WITH statement just before the aggregation:
WITH client, order, typeLevel
typeLevel is a value calculated in sponsorship tree traversal (combination of level and client type).
now the problem:
I need to aggregate by any of the 3 variables in the WITH statement above:
- client ( a node connected with Order with relationship)
- any order property
- typeLevel (dynamically calculated) value
and I can do that obviously by implementing at least 3 API methods (possibly more):
- sumOfOrderValuesByClient, sumOfOrderValuessByTypeLevel and sumOfOrderValuesByProperty
I only know how to make sumOfOrderValuesByProperty dynamic using order[property] notation, but is there a way to make the other two dynamic.
For example, I am thinking about passing the aggregation operation e.g sum, count, or avg and an order property that will be aggregated (e.g value or type or id) as parameters, so it becomes:
and also pass group by key:
order.type (a property of the order)
So, now I would have 9 API methods for 3 types of aggregation and 3 groupBy keys. Seems horrible
I do not really know how to do this in a dynamic way in a SINGLE graphql query.
I tried to create on the fly cypher query and pass it to the
apoc.cypher.* but apoc operates per row, so I am not getting aggregated values
Does anyone have an idea how to do that?