Find nodes by edge and child node ids

Hi, I have a product <values> attributeOption relation.

Now I am trying to find all products having a values edge and fulfil this filter:

$and: [$in:{attributeOption.id, [10, 20]}, $in:{attributeOption.id, [30, 40]}]

Here is how I would do it in SQL with n-m relationship:

 SELECT count(*) from "products" 
 join "productValues" as v1 on "v1"."productId" =  "products"."id" and "v1"."optionId" in (10, 20)
 join "productValues" as v2 on "v2"."productId" =  "products"."id" and "v2"."optionId" in (30, 40)

How can I do this in Dgraph ? Thanks!

{
   "type": "product",
   "id": 1,
   "label": "Computer",
   "values": [
      {
         "type": "AttributeOption",
         "id": 20,
         "label": "Dell"
      },
      {
         "type": "AttributeOption",
         "id": 30,
         "label": "HP"
      },
      {
         "type": "AttributeOption",
         "id": 40,
         "label": "20Gb"
      },
      {
         "type": "AttributeOption",
         "id": 50,
         "label": "40Gb"
      }
   ]
}

Something like this?

{
  q(func: eq(label, "Computer")){
    id
    label
    values @filter(eq(id, ["10", "20", "30", "40"])) {
      id
      label
    }
  }
}

That was my first guess too but it’s not quite what I am looking for. Because it returns products that don’t match the filter.

Assuming this is my source:


const test = [
  {
    type: "product",
    id: 1,
    label: "Computer 1",
    values: [
      {
        type: "AttributeOption",
        id: 20,
        label: "Dell"
      },
      {
        type: "AttributeOption",
        id: 40,
        label: "20Gb"
      }
    ]
  },
  {
    type: "product",
    id: 2,
    label: "Computer 2",
    values: [
      {
        type: "AttributeOption",
        id: 30,
        label: "HP"
      },
      {
        type: "AttributeOption",
        id: 40,
        label: "20Gb"
      }
    ]
  }
]

I want to run two queres:

eq(type, ‘product’) and eq(values.id, [20, 30]) and eq(values.id, [40]) => this should return both products
eq(type, ‘product’) and eq(values.id, [30]) and eq(values.id, [40]) => this should return product with id 2