How to delete an empty node?

The following code seems to delete all BlogPost.comments:

const txn = dgraphClient.newTxn();

export async function post(request) {
  const deleteBlogPostComments = {
    query: `{ c as var(func: type(Comment)) }`,
    delete: [
      {
        "uid": "uid(c)"
      }
    ]
  }

  await txn.mutate({ mutation: JSON.stringify(deleteBlogPostComments) });
  await txn.commit();
}

If I run queryComment I get an empty array, if I query aggregateComment(){ count } I get 0.

However, if I query:

query{
  getBlogPost(slug: "a-slug"){
    comments {
      id
    }
  }
}

…I still get a array of comment ids.

And if I query for:

query{
  getBlogPost(slug: "a-slug"){
    comments {
      id
      textContent
    }
  }
}

…I get:

"errors": [
    {
      "message": "Non-nullable field 'textContent' (type String!) was not present in result from Dgraph.  GraphQL error propagation triggered.",

Why does this happen?

Presumably I need to delete the edges from BlogPost to orphan nodes / orphan ids / whatever they are, and then this isn’t a problem anymore? I’m guessing the remaining IDs are merely edges that now link to nothing?

EDIT:

Presumably I need to delete the edges from BlogPost to orphan nodes / orphan ids / whatever they are, and then this isn’t a problem anymore?

To confirm, deleting these edges fixes the non-nullable field error, however, I still have the following questions:

  • Am I right in saying that the array of IDs are merely edges to nowhere?
  • How would I do the above (delete all BlogPost.comments with relevant edges) using RDF syntax in Ratel??

Here is a reference:

In theory, almost. Every uid list are “merely edges to nowhere” if that is how you want to look at it. A list of uids is a “list of uids” whether those uids have any triples stored in the graph or not.

Yourself coming from the GraphQL API down to the DQL lang itself you are seeing some of the power of the API that you don’t get. You have to now control the deletes of the * * O variety when Dgraph does not allow deletes of this variety.

In the API the schema shows everywhere possible for these uids to exist when being deleted and runs a S P O delete for each possible location where S is each possible pare node P is each edge and O is the node being deleted.

This again shows the need why we need something like the following not only in the GraphQL API, but also in the DQL language itself: