I want to get how many of each product was bought
I am trying with this query:
{
var(func: has(products)) @groupby(products) {
a as count(uid)
}
q(func: uid(a), orderdesc: val(a)) {
idProduct
productName
total_product : val(a)
}
}
Buy I am receiving the products without grouping
{
"data": {
"q": [
{
"idProduct": "2a80be10",
"productName": "La terra fina",
"total_product": 1
},
{
"idProduct": "bcd8f4a8",
"productName": "Rice A Roni Instant Chicken Flavor 1.97 Ounce Cup",
"total_product": 1
},
My schema is this:
op.Schema = `
id: string@index(exact) .
name: string .
age: int .
purchases: [uid]@count@reverse .
idPurchase: string .
idPerson: string .
ip: string@index(exact) .
device: string .
products: [uid] .
idProduct: string .
productName: string .
price: string .
`
<age>: int .
<device>: string .
<dgraph.graphql.schema>: string .
<id>: string @index(exact) .
<idPerson>: string .
<idProduct>: string .
<idPurchase>: string .
<ip>: string @index(exact) .
<name>: string .
<price>: string .
<productName>: string .
<products>: [uid] .
<purchases>: [uid] @count @reverse .
type <dgraph.graphql> {
dgraph.graphql.schema
}
Thank you in advance for any idea.