Upset using variable -DQL

Im using the below Mutation:

{
   "set":[
        {
            "uid":"_:jack",
            "xid": "jack",
            "name":"Jack",
            "dgraph.type": "Person"
        },
        {
           "uid":"_:bmw1122",
           "xid": "bmw1122",
           "vehicleNo":"bmw1122",
           "dgraph.type": "Vehicle",
           "model": "BMW 5 Series"
        },
        {
           "uid":"_:merc2233",
           "xid": "merc2233",
           "vehicleNo":"merc2233",
           "dgraph.type": "Vehicle",
           "model": "MERC CLS"
        },
                 
           {
            "uid": "_:jack",
          "owner":[{
            "nodes": { "uid": "_:bmw1122" },
             "edges": [{
                              "valuationDate": "2001-01-01",
                              "marketValue":"20k" }]
                  },
                    {
              "nodes": {  "uid": "_:merc2233" },
               "edges": [{
                              "valuationDate": "2002-0101",
                              "marketValue":"30k" }]
                              }]
             }
      
    ]
}

this should create

Jack → owner → IntermediateNode1 → nodes → bmw1122
                             IntermediateNode1 → edges → marketValue(20k)
Jack → owner → IntermediateNode2 → nodes → merc2233
                             IntermediateNode2 → edges → marketValue(30k)

What I want to do is add a mutation to create another edge attribute to the bmw1122
something like this

Jack → owner → IntermediateNode1 → nodes → bmw1122
IntermediateNode1 → edges → marketValue(20k)
IntermediateNode1 → edges → marketValue(15k)

The Mutation I used is

upsert {
  query {
  relExists as relEdge(func: has(name)) @filter(has(owner) AND eq(xid,"jack")) @cascade
  {
    name
      owner @filter(has(nodes))
      {
        n1 as n1:uid
        nodes @filter(eq(xid,"bmw1122"))
          {
            vehicleNo
          }
      }
  }
  }
  mutation @if(ge(len(relExists), 1) AND ge(len(n1), 1)) {
    set {
      uid(n1) <edges> _:edge .
      _:edge  <valuationDate> "2005-01-01" .
      _:edge  <marketValue> "15k" .
    }
  }
  }

When I query back to see the outcome of the mutation
it seems the new edge is added to both the IntermediateNode1 and IntermediateNode2
My expectation is it should be added to only IntermediateNode1.
Not sure what I missed?

The reason I had this intermediateNode is I need to keep historical properties of the Node
using facets I was unable to keep historical

What is the question?

You can edit the first post and paste it all there. And also you can use the code block with three ``` grave accents at the beginning of the code and also at the end closing the code block. The code block will prevent sanitation in your code.

thanks MichelDiz…
finally posted by question

I think cascade is buggy with Upsert Blocks. You may have to add an extra block in the query block to have a precise result.

BTW, your dataset design is quite strange. You should simplify it. Are you doing an “inception graph”?

Here is something you can try

upsert {
  query {
  relExists as relEdge(func: type(Person)) @filter(eq(xid,"jack") AND has(owner)) @cascade { 
    name
    Owner as owner {
      n1 as n1 : uid
      nodes @filter(eq(xid,"bmw1122")) {
        B as  uid
        vehicleNo
      }
    }
  }
    q(func: uid(Owner)) @filter(uid_in(nodes,uid(B)))  {
       tgt as uid
    }
    
  }
  mutation @if(eq(len(relExists), 1) AND eq(len(n1), 1)) {
    set {
      uid(tgt) <edges> _:edge .
      _:edge  <valuationDate> "2005-01-01" .
      _:edge  <marketValue> "15k" .
    }
  }

Thanks MichelDiz,

For my case in the mutation using eq, did nothing

I had to change it to “ge”…this worked

upsert {
  query {
  relExists as relEdge(func: type(Person)) @filter(eq(xid,"jack") AND has(owner)) @cascade { 
    name
    Owner as owner {
      n1 as n1 : uid
      nodes @filter(eq(xid,"bmw1122")) {
        B as  uid
        vehicleNo
      }
    }
  }

    q(func: uid(Owner)) @filter(uid_in(nodes,uid(B)))  {
       tgt as uid
    }
  }

  mutation @if(ge(len(relExists), 1) AND ge(len(n1), 1)) {
    set {
      uid(tgt) <edges> _:edge .
      _:edge  <valuationDate> "2005-01-01" .
      _:edge  <marketValue> "14k" .
    }
  }
  }

Regarding the dataset....can I know how I could simplify it?