Delete Root node and all of its hierarchy

I Want to Do

Delete a root node with all of its sub-nodes down to the leaves

Schema

<created_by>: uid .
<Artifact.module>: string .
<Artifact.name>: string @index(hash, trigram) .
<Artifact.cuid>: string .
<Artifact.tic>: datetime .
<Artifact.toc>: datetime .
<Artifact.last_updated>: datetime .
<Artifact.hosting_machine_name>: string .
<Artifact.input_of>: [uid] @reverse .
<Artifact.output_of>: uid @reverse .
<Artifact.extras>: string .
<Branch.name>: string @index(hash) .
<Branch.created_at>: datetime .
<Branch.last_updated>: datetime .
<Branch.change_mark>: string .
<Branch.versions>: [uid] @reverse .
<Branch.checked_out_from>: uid @reverse .
<Version.number>: string @index(exact, trigram) .
<Version.change_mark>: string .
<Version.git_commit>: string  .
<Version.created_at>: datetime .
<Version.last_updated>: datetime .
<Version.creation_type>: string .
<Version.previous>: uid @reverse .
<Version.published_from>: uid @count @reverse .
<Version.artifacts>: [uid] @count @reverse .

type <Artifact> {
    created_by
    Artifact.module
    Artifact.name
    Artifact.cuid
    Artifact.tic
    Artifact.toc
    Artifact.last_updated
    Artifact.hosting_machine_name
    Artifact.extras
    Artifact.input_of
    Artifact.output_of
}
type <Branch> {
	created_by
	Branch.name
	Branch.created_at
	Branch.last_updated
	Branch.change_mark
	Branch.versions
	Branch.checked_out_from
}
type <Version> {
	created_by
	Version.number
	Version.change_mark
	Version.git_commit
	Version.created_at
	Version.last_updated
	Version.creation_type
	Version.previous
	Version.published_from
	Version.artifacts
}

Each branch has a set of versions, and each version has a list of artifacts.
I want to delete a specific branch and all the data beneath it, along with all of the connections between nodes.
@MichelDiz How can I do that?

Thanks,
spinelsun

1 Like

Well, that type of procedure is easy with an upsert query and recurse.

e.g:

upsert {
  query {
    var(func: eq(myRoot, "structure 1")) @recurse {
      v as uid
      N1 as nested1
      N2 as nested2
      N3 as nested3
      N4 as nested4
      N5 as nested5
    }
  }

  mutation {
   delete {
      uid(v)  * * .
      uid(N1) * * .
      uid(N2) * * .
      uid(N3) * * .
      uid(N4) * * .
      uid(N5) * * .
    }
  }
}

This will delete all connected objects to the root. To delete incoming edges is a bit different. You will need the reverse index and add it in the recurse block. But you would delete as uid(Incoming) <connectedto> * .

1 Like