Compare Node children and make tree if they are different

To facilitate better answering of questions, if you have a question, please fill in the following info. Otherwise, please delete the template.

What I want to do

I want to compare two nodes and its children. If one of the child is different → show tree
Please list the high level idea of what you want to do

What I did

My data =

{
  "set": [
    {
      "entity": "story",
      "entity_name": "story1",
      "follows": {
        "entity": "intent",
        "entity_name": "intent_1",
        "follows": {
          "entity": "action",
          "entity_name": "action_1"
        }
      }
    },
    {
      "entity": "story",
      "entity_name": "story1",
      "follows": {
        "entity": "intent",
        "entity_name": "intent_1",
        "follows": {
          "entity": "action",
          "entity_name": "action_2"
        }
      }
    }
  ]
}
  1. A → B → C
  2. A → B → D

Result I want to get
A
:arrow_down_small:
B
:arrow_lower_left: :arrow_lower_right:
C D

     A
     │
     B
    ─└─ 
   │   │
   C   D

Please list the things you have tried.

Dgraph metadata

dgraph version

PASTE THE RESULTS OF dgraph version HERE.

1 Like

I don’t know of any way to do this on the server with a query.

How many top level A sets do you have to compare? You will probably have to do this on client side somewhere and filter with client script.

For this example I would stringify the JSON response on the client and then compare the strings in a filter script.

That’s a bit complicated. We don’t have an easy way to do Diff between nodes
You can try this

First: You need to select two nodes. Using pagination we can select the first and the second.
Second: Compare the values level to level.
Third: The result of the block “q” will have a single node and “count” will return 1. And the block “total” will have 2 if the nodes are different.
I’m using cascade directive

{
  G as var(func: has(entity) ) @filter(eq(entity, "story"))

  var(func: uid(G), first:1 ) {
    uid
    entity 
    L1 as entity_name
    follows {
      uid
      entity 
      L2 as entity_name
      follows {
        uid
        entity 
        L3 as entity_name
      }
    }
  }

  q(func: uid(G), first:2 ) @filter(eq(entity_name, val(L1))) @cascade
  {
    uid
    entity 
    entity_name
   a as count(uid)
    follows @filter(eq(entity_name, val(L2))) {
      uid
      entity 
      entity_name
      follows @filter(eq(entity_name, val(L3))){
        uid
        entity 
        entity_name
      }
    }

  }
    total(){
    sum(val(a))
    }
      
}