Deletion with upsert is not working

What I want to do

I want to delete a node and its all child nodes recursively

What I did

I have come up with a query but it is deleting a specific node data and not the entire node. Also children are not deleted, not even their data

Dgraph metadata

dgraph version

dgraph version : v22.0.2

This is my schema:

<branches>: [uid] @reverse .
<child_groups>: [uid] @reverse .
<created>: datetime .
<dgraph.drop.op>: string .
<dgraph.graphql.p_query>: string @index(sha256) .
<dgraph.graphql.schema>: string .
<dgraph.graphql.xid>: string @index(exact) @upsert .
<hits>: int .
<manual>: bool .
<state>: int .
<text>: string .
<type>: string .
type <Branch> {
	text
	state
	created
	manual
	hits
}
type <Group> {
	text
	state
	created
	manual
	hits
}
type <dgraph.graphql> {
	dgraph.graphql.schema
	dgraph.graphql.xid
}
type <dgraph.graphql.persisted_query> {
	dgraph.graphql.p_query
}

I am running this query:

upsert {
      query {
        q(func: uid("0x9c49")) @recurse @normalize {
          all_ids as uid
          Branch.Group
          Group.Branch
        }
      }

      mutation {
        delete {
          uid(all_ids) * * .
        }
      }
    }

Are you sure the query is actually traversing all connected nodes? Based on your schema, the query should include the predicates branches and child_groups.

1 Like

Those predicates doesn’t exist in your schema.

Surely you are confusing the schema model used in GraphQL with the DQL. If you want to use the same GraphQL schema model you should change your dataset and DQL schema to use Type as a prefix.

This query is also not working

 upsert {
      query {
        q(func: uid("0x9c49")) @recurse @normalize {
          all_ids as uid
          branches.child_groups
          child_groups.branches
        }
      }

      mutation {
        delete {
          uid(all_ids) * * .
        }
      }
    }

This is how I am querying the graph recursively which is working fine:

{
      query(func: type(Branch)) {
        uid
        state
        created
    text
   type:  dgraph.type
        child_groups {
          uid
          state
          created
          text
          type: dgraph.type
          BRC as branches
        }
      }
      rq(func: uid(BRC)) @recurse {
        uid
        created
        state
        text
        type:dgraph.type
        child_groups
        branches
      }
    }

Response:

{
  "data": {
    "query": [
      {
        "uid": "0x1",
        "state": 14600,
        "created": "1969-12-31T18:00:00Z",
        "text": "string",
        "type": [
          "Branch"
        ],
        "child_groups": [
          {
            "uid": "0x2"
          }
        ]
      },
      {
        "uid": "0x2711",
        "state": 0,
        "created": "1969-12-31T18:00:00Z",
        "text": "string 2",
        "type": [
          "Branch"
        ],
        "child_groups": [
          {
            "uid": "0x2712",
            "state": 0,
            "created": "1969-12-31T18:00:00Z",
            "text": "string",
            "type": [
              "Group"
            ]
          }
        ]
      },
      {
        "uid": "0x2713",
        "state": 0,
        "created": "1969-12-31T18:00:00Z",
        "text": "string 2",
        "type": [
          "Branch"
        ],
        "child_groups": [
          {
            "uid": "0x2718",
            "state": 0,
            "created": "1969-12-31T18:00:00Z",
            "text": "string",
            "type": [
              "Group"
            ]
          },
          {
            "uid": "0x9c41",
            "state": 0,
            "created": "1969-12-31T18:00:00Z",
            "text": "string",
            "type": [
              "Group"
            ]
          },
          {
            "uid": "0x9c42",
            "state": 0,
            "created": "1969-12-31T18:00:00Z",
            "text": "string",
            "type": [
              "Group"
            ]
          }
        ]
      },
      {
        "uid": "0x2714",
        "state": 0,
        "created": "1969-12-31T18:00:00Z",
        "text": "string 2",
        "type": [
          "Branch"
        ],
        "child_groups": [
          {
            "uid": "0x4e21",
            "state": 0,
            "created": "1969-12-31T18:00:00Z",
            "text": "string",
            "type": [
              "Group"
            ]
          },
          {
            "uid": "0x4e22",
            "state": 0,
            "created": "1969-12-31T18:00:00Z",
            "text": "string",
            "type": [
              "Group"
            ]
          }
        ]
      },
      {
        "uid": "0x2715",
        "state": 0,
        "created": "1969-12-31T18:00:00Z",
        "text": "string 2",
        "type": [
          "Branch"
        ]
      },
      {
        "uid": "0x2716",
        "state": 0,
        "created": "1969-12-31T18:00:00Z",
        "text": "string 2",
        "type": [
          "Branch"
        ]
      },
      {
        "uid": "0x2717",
        "state": 0,
        "created": "1969-12-31T18:00:00Z",
        "text": "string 2",
        "type": [
          "Branch"
        ]
      },
      {
        "uid": "0x4e23",
        "state": 0,
        "created": "1969-12-31T18:00:00Z",
        "text": "string child",
        "type": [
          "Branch"
        ]
      },
      {
        "uid": "0x4e24",
        "state": 0,
        "created": "1969-12-31T18:00:00Z",
        "text": "another string child",
        "type": [
          "Branch"
        ]
      },
      {
        "uid": "0x4e25",
        "state": 0,
        "created": "1969-12-31T18:00:00Z",
        "text": "another string child",
        "type": [
          "Branch"
        ]
      },
      {
        "uid": "0x4e26",
        "state": 0,
        "created": "1969-12-31T18:00:00Z",
        "text": "another string child one more",
        "type": [
          "Branch"
        ]
      },
      {
        "uid": "0x7531",
        "state": 0,
        "created": "1969-12-31T18:00:00Z",
        "text": "A new branch",
        "type": [
          "Branch"
        ]
      },
      {
        "uid": "0x7532",
        "state": 172800,
        "created": "1970-01-02T18:00:00Z",
        "text": "another branch",
        "type": [
          "Branch"
        ]
      },
      {
        "uid": "0x9c43",
        "state": 0,
        "created": "1969-12-31T18:00:00Z",
        "text": "A Root Branch",
        "type": [
          "Branch"
        ],
        "child_groups": [
          {
            "uid": "0x9c44",
            "state": 1468800,
            "created": "1970-01-17T18:00:00Z",
            "text": "First level group",
            "type": [
              "Group"
            ]
          }
        ]
      },
      {
        "uid": "0x9c45",
        "state": 0,
        "created": "1969-12-31T18:00:00Z",
        "text": "first branch of first group",
        "type": [
          "Branch"
        ]
      },
      {
        "uid": "0x9c46",
        "state": 0,
        "created": "1969-12-31T18:00:00Z",
        "text": "One more branch",
        "type": [
          "Branch"
        ],
        "child_groups": [
          {
            "uid": "0x9c47",
            "state": 0,
            "created": "1969-12-31T18:00:00Z",
            "text": "A new group for child branch",
            "type": [
              "Group"
            ]
          }
        ]
      },
      {
        "uid": "0x9c48",
        "state": 0,
        "created": "1969-12-31T18:00:00Z",
        "text": "third branch",
        "type": [
          "Branch"
        ],
        "child_groups": [
          {
            "uid": "0x9c49"
          }
        ]
      },
      {
        "uid": "0x9c4a",
        "state": 0,
        "created": "1969-12-31T18:00:00Z",
        "text": "A new branch",
        "type": [
          "Branch"
        ],
        "child_groups": [
          {
            "uid": "0xc351",
            "state": 0,
            "created": "1969-12-31T18:00:00Z",
            "text": "A new group",
            "type": [
              "Group"
            ]
          }
        ]
      },
      {
        "uid": "0x9c4b",
        "state": 0,
        "created": "1969-12-31T18:00:00Z",
        "text": "another branch",
        "type": [
          "Branch"
        ]
      },
      {
        "uid": "0x9c4c",
        "state": 0,
        "created": "1969-12-31T18:00:00Z",
        "text": "Another branch",
        "type": [
          "Branch"
        ]
      },
      {
        "uid": "0x9c4d",
        "state": 0,
        "created": "1969-12-31T18:00:00Z",
        "text": "another b",
        "type": [
          "Branch"
        ]
      },
      {
        "uid": "0x9c4e",
        "state": 0,
        "created": "1969-12-31T18:00:00Z",
        "text": "fifth branch",
        "type": [
          "Branch"
        ]
      },
      {
        "uid": "0x9c4f",
        "state": 0,
        "created": "1969-12-31T18:00:00Z",
        "text": "sixth branch",
        "type": [
          "Branch"
        ]
      },
      {
        "uid": "0x9c50",
        "state": 0,
        "created": "1969-12-31T18:00:00Z",
        "text": "seventh branch",
        "type": [
          "Branch"
        ]
      },
      {
        "uid": "0x9c51",
        "state": 0,
        "created": "1969-12-31T18:00:00Z",
        "text": "eight branch",
        "type": [
          "Branch"
        ]
      },
      {
        "uid": "0x9c52",
        "state": 0,
        "created": "1969-12-31T18:00:00Z",
        "text": "ninth branch",
        "type": [
          "Branch"
        ],
        "child_groups": [
          {
            "uid": "0x9c55",
            "state": 0,
            "created": "1969-12-31T18:00:00Z",
            "text": "a group for y",
            "type": [
              "Group"
            ]
          }
        ]
      },
      {
        "uid": "0x9c53",
        "state": 0,
        "created": "1969-12-31T18:00:00Z",
        "text": "tenth branch",
        "type": [
          "Branch"
        ],
        "child_groups": [
          {
            "uid": "0x9c54",
            "state": 0,
            "created": "1969-12-31T18:00:00Z",
            "text": "new group",
            "type": [
              "Group"
            ]
          }
        ]
      },
      {
        "uid": "0xc352",
        "state": 0,
        "created": "1969-12-31T18:00:00Z",
        "text": "A new branch for uz0",
        "type": [
          "Branch"
        ],
        "child_groups": [
          {
            "uid": "0xc353",
            "state": 0,
            "created": "2023-04-20T06:19:33.367238Z",
            "text": "abcdef",
            "type": [
              "Group"
            ]
          }
        ]
      }
    ],
    "rq": [
      {
        "uid": "0x2713",
        "created": "1969-12-31T18:00:00Z",
        "state": 0,
        "text": "string 2",
        "type": [
          "Branch"
        ],
        "child_groups": [
          {
            "uid": "0x2718",
            "created": "1969-12-31T18:00:00Z",
            "state": 0,
            "text": "string",
            "type": [
              "Group"
            ],
            "branches": [
              {
                "uid": "0x4e23",
                "created": "1969-12-31T18:00:00Z",
                "state": 0,
                "text": "string child",
                "type": [
                  "Branch"
                ]
              },
              {
                "uid": "0x4e24",
                "created": "1969-12-31T18:00:00Z",
                "state": 0,
                "text": "another string child",
                "type": [
                  "Branch"
                ]
              },
              {
                "uid": "0x4e25",
                "created": "1969-12-31T18:00:00Z",
                "state": 0,
                "text": "another string child",
                "type": [
                  "Branch"
                ]
              },
              {
                "uid": "0x4e26",
                "created": "1969-12-31T18:00:00Z",
                "state": 0,
                "text": "another string child one more",
                "type": [
                  "Branch"
                ]
              }
            ]
          },
          {
            "uid": "0x9c41",
            "created": "1969-12-31T18:00:00Z",
            "state": 0,
            "text": "string",
            "type": [
              "Group"
            ]
          },
          {
            "uid": "0x9c42",
            "created": "1969-12-31T18:00:00Z",
            "state": 0,
            "text": "string",
            "type": [
              "Group"
            ]
          }
        ]
      },
      {
        "uid": "0x2714",
        "created": "1969-12-31T18:00:00Z",
        "state": 0,
        "text": "string 2",
        "type": [
          "Branch"
        ],
        "child_groups": [
          {
            "uid": "0x4e21",
            "created": "1969-12-31T18:00:00Z",
            "state": 0,
            "text": "string",
            "type": [
              "Group"
            ]
          },
          {
            "uid": "0x4e22",
            "created": "1969-12-31T18:00:00Z",
            "state": 0,
            "text": "string",
            "type": [
              "Group"
            ]
          }
        ]
      },
      {
        "uid": "0x2715",
        "created": "1969-12-31T18:00:00Z",
        "state": 0,
        "text": "string 2",
        "type": [
          "Branch"
        ]
      },
      {
        "uid": "0x2716",
        "created": "1969-12-31T18:00:00Z",
        "state": 0,
        "text": "string 2",
        "type": [
          "Branch"
        ]
      },
      {
        "uid": "0x2717",
        "created": "1969-12-31T18:00:00Z",
        "state": 0,
        "text": "string 2",
        "type": [
          "Branch"
        ]
      },
      {
        "uid": "0x4e23",
        "created": "1969-12-31T18:00:00Z",
        "state": 0,
        "text": "string child",
        "type": [
          "Branch"
        ]
      },
      {
        "uid": "0x4e24",
        "created": "1969-12-31T18:00:00Z",
        "state": 0,
        "text": "another string child",
        "type": [
          "Branch"
        ]
      },
      {
        "uid": "0x4e25",
        "created": "1969-12-31T18:00:00Z",
        "state": 0,
        "text": "another string child",
        "type": [
          "Branch"
        ]
      },
      {
        "uid": "0x4e26",
        "created": "1969-12-31T18:00:00Z",
        "state": 0,
        "text": "another string child one more",
        "type": [
          "Branch"
        ]
      },
      {
        "uid": "0x7531",
        "created": "1969-12-31T18:00:00Z",
        "state": 0,
        "text": "A new branch",
        "type": [
          "Branch"
        ]
      },
      {
        "uid": "0x7532",
        "created": "1970-01-02T18:00:00Z",
        "state": 172800,
        "text": "another branch",
        "type": [
          "Branch"
        ]
      },
      {
        "uid": "0x9c45",
        "created": "1969-12-31T18:00:00Z",
        "state": 0,
        "text": "first branch of first group",
        "type": [
          "Branch"
        ]
      },
      {
        "uid": "0x9c46",
        "created": "1969-12-31T18:00:00Z",
        "state": 0,
        "text": "One more branch",
        "type": [
          "Branch"
        ],
        "child_groups": [
          {
            "uid": "0x9c47",
            "created": "1969-12-31T18:00:00Z",
            "state": 0,
            "text": "A new group for child branch",
            "type": [
              "Group"
            ]
          }
        ]
      },
      {
        "uid": "0x9c48",
        "created": "1969-12-31T18:00:00Z",
        "state": 0,
        "text": "third branch",
        "type": [
          "Branch"
        ],
        "child_groups": [
          {
            "uid": "0x9c49",
            "branches": [
              {
                "uid": "0x9c4a",
                "created": "1969-12-31T18:00:00Z",
                "state": 0,
                "text": "A new branch",
                "type": [
                  "Branch"
                ]
              },
              {
                "uid": "0x9c4b",
                "created": "1969-12-31T18:00:00Z",
                "state": 0,
                "text": "another branch",
                "type": [
                  "Branch"
                ]
              },
              {
                "uid": "0x9c4c",
                "created": "1969-12-31T18:00:00Z",
                "state": 0,
                "text": "Another branch",
                "type": [
                  "Branch"
                ]
              },
              {
                "uid": "0x9c4d",
                "created": "1969-12-31T18:00:00Z",
                "state": 0,
                "text": "another b",
                "type": [
                  "Branch"
                ]
              },
              {
                "uid": "0x9c4e",
                "created": "1969-12-31T18:00:00Z",
                "state": 0,
                "text": "fifth branch",
                "type": [
                  "Branch"
                ]
              },
              {
                "uid": "0x9c4f",
                "created": "1969-12-31T18:00:00Z",
                "state": 0,
                "text": "sixth branch",
                "type": [
                  "Branch"
                ]
              },
              {
                "uid": "0x9c50",
                "created": "1969-12-31T18:00:00Z",
                "state": 0,
                "text": "seventh branch",
                "type": [
                  "Branch"
                ]
              },
              {
                "uid": "0x9c51",
                "created": "1969-12-31T18:00:00Z",
                "state": 0,
                "text": "eight branch",
                "type": [
                  "Branch"
                ]
              },
              {
                "uid": "0x9c52",
                "created": "1969-12-31T18:00:00Z",
                "state": 0,
                "text": "ninth branch",
                "type": [
                  "Branch"
                ]
              },
              {
                "uid": "0x9c53",
                "created": "1969-12-31T18:00:00Z",
                "state": 0,
                "text": "tenth branch",
                "type": [
                  "Branch"
                ]
              }
            ]
          }
        ]
      },
      {
        "uid": "0x9c4a",
        "created": "1969-12-31T18:00:00Z",
        "state": 0,
        "text": "A new branch",
        "type": [
          "Branch"
        ],
        "child_groups": [
          {
            "uid": "0xc351",
            "created": "1969-12-31T18:00:00Z",
            "state": 0,
            "text": "A new group",
            "type": [
              "Group"
            ]
          }
        ]
      },
      {
        "uid": "0x9c4b",
        "created": "1969-12-31T18:00:00Z",
        "state": 0,
        "text": "another branch",
        "type": [
          "Branch"
        ]
      },
      {
        "uid": "0x9c4c",
        "created": "1969-12-31T18:00:00Z",
        "state": 0,
        "text": "Another branch",
        "type": [
          "Branch"
        ]
      },
      {
        "uid": "0x9c4d",
        "created": "1969-12-31T18:00:00Z",
        "state": 0,
        "text": "another b",
        "type": [
          "Branch"
        ]
      },
      {
        "uid": "0x9c4e",
        "created": "1969-12-31T18:00:00Z",
        "state": 0,
        "text": "fifth branch",
        "type": [
          "Branch"
        ]
      },
      {
        "uid": "0x9c4f",
        "created": "1969-12-31T18:00:00Z",
        "state": 0,
        "text": "sixth branch",
        "type": [
          "Branch"
        ]
      },
      {
        "uid": "0x9c50",
        "created": "1969-12-31T18:00:00Z",
        "state": 0,
        "text": "seventh branch",
        "type": [
          "Branch"
        ]
      },
      {
        "uid": "0x9c51",
        "created": "1969-12-31T18:00:00Z",
        "state": 0,
        "text": "eight branch",
        "type": [
          "Branch"
        ]
      },
      {
        "uid": "0x9c52",
        "created": "1969-12-31T18:00:00Z",
        "state": 0,
        "text": "ninth branch",
        "type": [
          "Branch"
        ],
        "child_groups": [
          {
            "uid": "0x9c55",
            "created": "1969-12-31T18:00:00Z",
            "state": 0,
            "text": "a group for y",
            "type": [
              "Group"
            ]
          }
        ]
      },
      {
        "uid": "0x9c53",
        "created": "1969-12-31T18:00:00Z",
        "state": 0,
        "text": "tenth branch",
        "type": [
          "Branch"
        ],
        "child_groups": [
          {
            "uid": "0x9c54",
            "created": "1969-12-31T18:00:00Z",
            "state": 0,
            "text": "new group",
            "type": [
              "Group"
            ],
            "branches": [
              {
                "uid": "0xc352",
                "created": "1969-12-31T18:00:00Z",
                "state": 0,
                "text": "A new branch for uz0",
                "type": [
                  "Branch"
                ]
              }
            ]
          }
        ]
      },
      {
        "uid": "0xc352",
        "created": "1969-12-31T18:00:00Z",
        "state": 0,
        "text": "A new branch for uz0",
        "type": [
          "Branch"
        ],
        "child_groups": [
          {
            "uid": "0xc353",
            "created": "2023-04-20T06:19:33.367238Z",
            "state": 0,
            "text": "abcdef",
            "type": [
              "Group"
            ]
          }
        ]
      }
    ]
  },
  "extensions": {
    "server_latency": {
      "parsing_ns": 46197,
      "processing_ns": 2072280,
      "encoding_ns": 210476,
      "assign_timestamp_ns": 346146,
      "total_ns": 2756753
    },
    "txn": {
      "start_ts": 140054
    },
    "metrics": {
      "num_uids": {
        "": 0,
        "_total": 609,
        "branches": 65,
        "child_groups": 79,
        "created": 93,
        "dgraph.type": 93,
        "state": 93,
        "text": 93,
        "uid": 93
      }
    }
  }
}

Same as before. Looks like I failed to explain it.

The “word dot word” (w. w) pattern does not exist by default in DQL. It is a feature of GraphQL modeling that we use there. Please do not confuse the two.

Based on analyzing your schema, the query should be something like this. Also, please remove the @normalize directive as it has no effect in this context.

{
        q(func: uid("0x9c49")) @recurse {
          all_ids as uid
          branches
          child_groups
        }
      }

The best and safe should be like

 upsert {
      query {
        q(func: uid("0x9c49")) @recurse  {
          uid
          b as branches
          c as child_groups
        }
      }

      mutation {
        delete {
          uid(b) * * .
          uid(c) * * .
        }
      }
    }

This query does not seem to delete the node and child nodes, though I am not able to view the node data, but the node is still there with its uid.

I want to delete all these child nodes along with the node whose uid I provide.

Screenshot from 2023-04-24 15-45-18

I can still query these nodes using the ‘query’ I shared earlier to view their data which shows that the node is not actually deleted.

Any update on this @MichelDiz

Even running this doesn’t delete the node


{
	delete {
    <0x9c49> * * .
	}
}

Well, the problem relies on your side. I don’t have access to it or time to look at somehow. The issue certentanly is much simpler. It might be your schema, missing the dgraph.type correct, or the type is wrong missing the correct predicates. Check one by one. I can’t tell what it is from what you have shared.

If your data and you schema is not aligned. Some functions like delete won’t work.

I am writing to request your assistance with Dgraph query and schema as I am new to this technology and still learning the ropes. I understand that you have experience in this field and I would greatly appreciate it if you could spare some time to help me out.

In order to make the most of your time and expertise, could you please let me know what additional information you may need from me to help me out? I am more than happy to provide any details or examples that may be necessary to ensure that you can provide the best possible assistance.

Thank you in advance for your help and support. I look forward to hearing from you soon.

Hi Ritik,

I understand that you may are new to both DQL and GraphQL, and you can expect a learning curve of a few months. I recommend starting with our tour at https://tour.dgraph.io/, which covers both DQL and GraphQL basics.

Regarding GraphQL, you can use any GraphQL tutorial out there. There are hours of content on YouTube that are applicable to Dgraph. However, there are slight differences since Dgraph makes extensive use of directives to create a more customized experience. Additionally, Dgraph automatically generates GraphQL backends based on your schema, which is quite different from many other GraphQL products. This greatly aids developers in building applications quickly.

Underneath of Dgraph’s GraphQL, there’s a standard or convention that shapes the GraphQL schema. It’s a bit complex to explain how it works without writing lengthy pages to someone who isn’t deeply familiar with GraphQL. In fact, you don’t need to know all of the details, as Dgraph is designed to abstract a lot of things for you. However, if you’re interested in using DQL, it’s important to note that doing so may make things more complex than necessary.

Regarding DQL, you’ll need to have a well-defined schema and ensure that objects contain the correct dgraph.type. If either of these aspects is incorrect, functions like Delete wont work.

If you follow the quick start guide at Quick Start - DQL, you’ll get an idea of how things work. When learning something new, it’s best to start with basic tasks like CRUD operations before diving into more complex features.

If you could share any small examples that aren’t working for you, along with a step-by-step description of what you’ve tried, that would be a great starting point.

Looking forward to helping you further.

Cheers!

PS. Take a look at this New to Dgraph? DQL vs. GraphQL, Endpoints, Headers, and Schema Translation

I have a very simple question:

When I delete a node using:

{
	delete {
    <0x11178> * * .
	}
}

It deletes all the predicates except the uid. Refer to the screenshot.

Screenshot from 2023-04-26 18-38-31

Is it the desired behaviour of dgraph? How to delete this uid predicate also. I just want the node to disappear.

I tried this also, but no affects.

        delete {
          <0x11178> * * .
           <0x11178> <uid> * .
        }

Not quite correct. The delete S** method in the recent versions somewhere was changed to only delete the predicates that exist in the type system for the given type of the node. For example if you manually delete or change the dgraph.type predicate then the delete will not work as expected. I’m going to open an issue about this with another idea I had while reading this post.

And more importantly…

uid predicates will ALWAYS exist and NEVER exist at the same time. Here is a relative post:

But I am not able to add ‘uid’ predicate to the type system as it is a keyword.

uid predicates will ALWAYS exist and NEVER exist at the same time.

I am querying the graph using the type system and I am receiving the node always even after deletion (in case the uid always exist and never exist at the same time)

How to only query those Ids which Always Exists?

This is the query I am using (schema is shared here):

 query query($a: string) {
    query(func: uid($a)) {
        uid
        state
        created
        type: dgraph.type
        child_groups {
          uid
          state
          created
          type: dgraph.type
          BRC as branches
        }
      }
      rq(func: uid(BRC)) @recurse {
        uid
        created
        state
        type: dgraph.type
        child_groups
        branches
      }
    }

if you are forcing use of dgraph.type and not using schemaless design, then you should modify this with an additional filter check for the type like:

query query($a: string) {
    query(func: uid($a)) @filter(has(dgraph.type)) {
        uid
        state
        created
        type: dgraph.type
        child_groups @filter(has(dgraph.type)) {
          uid
          state
          created
          type: dgraph.type
          BRC as branches @filter(has(dgraph.type))
        }
      }
      rq(func: uid(BRC)) @filter(has(dgraph.type)) @recurse {
        uid
        created
        state
        type: dgraph.type
        child_groups @filter(has(dgraph.type))
        branches @filter(has(dgraph.type))
      }
    }

Did you read the other post I linked?? You don’t put the uid in your types. And you can’t delete it…

1 Like

Did you read the other post I linked?? You don’t put the uid in your types. And you can’t delete it…

yes, I read it.

Your suggestion really helped.

I have one more question.

I am running this query to recursively delete the node and its all children, it is deleting the children but not deleting itself. Could you guide me on this too?

 upsert {
      query {
        q(func: uid($a)) @recurse {
          uid
          b as branches
          c as child_groups
        }
      }

      mutation {
        delete {
          <$a> * * .
          uid(b) * * .
          uid(c) * * .
        }
      }
    }

$a is the uid.

Have you tried:

 upsert {
      query {
        a as q(func: uid($a)) @recurse {
          uid
          b as branches
          c as child_groups
        }
      }

      mutation {
        delete {
          uid(a) * * .
          uid(b) * * .
          uid(c) * * .
        }
      }
    }

Tried this but not working.

explain “not working” what are you querying after this upsert delete, and what is the response?

Seems like this is working fine on ratel. I will have another look at the code level.

This is how I am doing this in python.

def delete_grouping(group_or_branch_uid: str) -> tuple:
    print(group_or_branch_uid, "deleting queryyyyyyyyy")
    query = """
     upsert {
      query {
        a as q(func: uid($a)) @recurse {
          uid
          b as branches
          c as child_groups
        }
      }

      mutation {
        delete {
          uid(a) * * .
          uid(b) * * .
          uid(c) * * .
        }
      }
    }
    """

    def delete_query(_q: str, _vars: dict):
        txn = client.txn(read_only=False)
        try:
            txn.async_query(_q, _vars)
            txn.commit()
        finally:
            txn.discard()

    return delete_query, query, {"$a": group_or_branch_uid}

Hello @amaster507, Could you help me with this.

I have this query before deletion:

    upsert varQuery($a: string) {
      query {
        a as q(func: uid($a)) @recurse {
          uid
          b as branches
          c as child_groups
        }
      }
      mutation {
        delete {
          uid(a) * * .
          uid(b) * * .
          uid(c) * * .
        }
      }
    }

and this is the variable I am passing.

{'$a': '0x1388a'}

Earlier, upsert does not take variables. but as of now it should take variables.

I am doing the transaction this way:

txn = client.txn(read_only=False)
        try:
            txn.async_mutate(_q, _vars)
            txn.commit()
        finally:
            txn.discard()

Is there anything I am missing here as this is not working on the code level.

I have tried the following methods:

txn.async_query, txn.async_mutate, txn_async_do_request