Update Reverse

Hi,

I have the following data set:

      {
        "Repository.name": "evolve",
        "Repository.owner": {
          "User.username": "spinelsun",
          "uid": "0x51"
        }
      },
      {
        "Repository.name": "orkestro",
        "Repository.owner": {
          "User.username": "michalush",
          "uid": "0x50"
        }
      }
    ]

when I update the repository owner of orkestro the owner does changes but the reverse owner doesn’t:

update

upsert{
  query{
    q(func: eq(Repository.name, "orkestro")){
      v as uid
    }
  }
  mutation {
      set {
         uid(v) <Repository.owner> <0x51> .
      }
   }
}


result after update

 "repos": [
      {
        "Repository.name": "evolve",
        "Repository.owner": {
          "User.username": "spinelsun",
          "uid": "0x51"
        }
      },
      {
        "Repository.name": "orkestro",
        "Repository.owner": {
          "User.username": "spinelsun",
          "uid": "0x51"
        }
      }
    ]

but in the reverse direction, the data doesn’t update:

"users": [
      {
        "User.username": "michalush",
        "uid": "0x50",
        "~Repository.owner": [
          {
            "Repository.name": "orkestro"
          }
        ]
      },
      {
        "User.username": "spinelsun",
        "uid": "0x51",
        "~Repository.owner": [
          {
            "Repository.name": "evolve"
          },
          {
            "Repository.name": "orkestro"
          }
        ]
      }
   ]

I get the same result if michalush is the owner of orkestro - orkestro should be removed from the reverse direction if the user is not the owner of it anymore.
What happens now is that in the reverse direction the data doesn’t being replaced but summed up for some reason

My question is why?

The incoming edge will exist cuz it is information that lives in the parent node and not the child one. If you wanna change that relation you have to remove the parent first and then add a new parent.

can you share an example.
I am not sure which ine is the parent and which is the child.
Repository has a reference to a user via the predicate Repository.owner which has a @revers directive.

<Repository.owner>: uid @reverse .
<User.username>: string @index(hash, trigram) @upsert .

type <User> {
	User.username
}
type <Repository> {
    Repository.owner
}

If I change the repository owner in the repository node the reverse from the user node should be updated to isn’t it?

Something like this

upsert{
  query{
    v as q(func: eq(Repository.name, "orkestro"))
  }
  mutation {
      delete {
         uid(v) <Repository.owner> * .
      }
      set {
         uid(v) <Repository.owner> <0x51> .
      }
   }
}

I’m trying to achieve the same but old parent still contains the reverse edge node. Even when I delete the complete child it’s uid is still present in reverse edge node of parent.

1 Like

You should do something like this @Gurpreet_Sharma

PS. You need to have the reverse edge directive in the parent predicate.

upsert{
  query{
    v as q(func: eq(Repository.name, "orkestro")) {
       DelParentLink as <~Parent>
}
  }
  mutation {
      delete {
         uid(v) <Repository.owner> * .
         uid(DelParentLink) <Parent> uid(v) .
      }
      set {
         uid(v) <Repository.owner> <0x51> .
      }
   }
}

Here “orkestro” does not have any reverse egde node, it’s parent “spinelsun” has that which we want to delete. So, I’m a little confused please help me out what is meant by according to the above data set as example?

So this is the dataset:

{
        "uid": "0x75c6c",
        "metadata.equipment.type": "datacenter",
        "~metadata.equipment.parent": [
          {
            "uid": "0x75c70",
            "metadata.equipment.type": "vcenter"
          }
        ]
      },
      {
        "uid": "0x75c70",
        "metadata.equipment.type": "vcenter",
        "metadata.equipment.parent": {
          "uid": "0x75c6c",
          "metadata.equipment.type": "datacenter"
        },
        "~metadata.equipment.parent": [
          {
            "uid": "0x75c72",
            "metadata.equipment.type": "cluster"
          }
        ]
      },
      {
        "uid": "0x75c72",
        "metadata.equipment.type": "cluster",
        "metadata.equipment.parent": {
          "uid": "0x75c70",
          "metadata.equipment.type": "vcenter"
        }
      }

Here I need to chnge the “metadata.equipment.parent” node of “cluster” to “datacenter” i.e. expected dataset after update should be:

 {
        "uid": "0x75c6c",
        "metadata.equipment.type": "datacenter",
        "~metadata.equipment.parent": [
          {
            "uid": "0x75c70",
            "metadata.equipment.type": "vcenter"
          },
         {
            "uid": "0x75c72",
            "metadata.equipment.type": "cluster"
          }
        ]
      },
      {
        "uid": "0x75c70",
        "metadata.equipment.type": "vcenter",
        "metadata.equipment.parent": {
          "uid": "0x75c6c",
          "metadata.equipment.type": "datacenter"
        },
      },
      {
        "uid": "0x75c72",
        "metadata.equipment.type": "cluster",
        "metadata.equipment.parent": {
           "uid": "0x75c6c",
        "metadata.equipment.type": "datacenter"
        }
      }

I’m using the above suggested query for upsert:

upsert{
  query{
    v as q(func: eq(metadata.equipment.type, "cluster")) @filter(eq(scopes,BUG))
  }
  mutation {
      delete {
         uid(v) <metadata.equipment.parent> * .
      }
      set {
         uid(v) <metadata.equipment.parent> <0x75c6c> .
      }
   }
}

Result is:

{
        "uid": "0x75c6c",
        "metadata.equipment.type": "datacenter",
        "~metadata.equipment.parent": [
          {
            "uid": "0x75c70",
            "metadata.equipment.type": "vcenter"
          }
        ]
      },
      {
        "uid": "0x75c70",
        "metadata.equipment.type": "vcenter",
        "metadata.equipment.parent": {
          "uid": "0x75c6c",
          "metadata.equipment.type": "datacenter"
        }
      },
      {
        "uid": "0x75c72",
        "metadata.equipment.type": "cluster"
      }

Here old parent seems to be deleted but new parent is not set. Can you please help me find what could be the problem here?

Hello, since I had to use dgo client to run these mutations. I final working solution for me was to use two different transactions. One is the above provided upsert query without set block and other is to set nquads. This works in my situation.