Find All Nodes And Edges

I’m trying to find a way to get a total count of all the nodes and all the edges in my graph.

I tried something like

counting(func: has(dgraph.type)) {
  a as uid
  b as predicate1
  c as predicate2
  d as math(a+b)

result () {
  node_total: count(a)
  edge_total: count(d)

but the query never returns.

If I remove the math on the predicates and just count uids then the query returns in about 10 minutes which isn’t great.

Is there no other way to get counts of nodes and edges? I’ve looked at the metrics and debug output but those don’t have what I’m looking for.


To get all nodes count:

query {
  counter(func: has(dgraph.type)) {

Edges are facets in dgraph, so you need to use the @facet directive

and more on counters:

For specific questions, I suggest you get on the discord to get a quick answer:


1 Like
  1. Your query, will only query nodes that have a set dgraph.type predicate. And it is possible that not all nodes have that.

  2. What? facets, don’t have anything to do with edges. Facets are on edges, but are not the edges.

  1. to get the data you are wanting, export your data and then process the export counting your nodes and your edges from the exported data file. Good luck.

So I was assuming here they are adding mutations the recommended way. It would be arguably corrupt data otherwise.

This is semantics. You need to use @facet to set these properties.