Return all the nodes a graph as a list using the golang client

To “Flat” things we use normalize. But, for your case, this would messup with everything. There’s no function in Dgraph that returns a flat line of objects. What you can do is use variables and multiple blocks to have the same result.

e.g:

PS. “idval” is a list. So it will be always like "idval": ["uuid2"]
and not "idval": "uuid2"

{
  var(func: eq(dgraph.type, "IdNode"), first:1) @recurse {
    VAR0 as uid #This will get all UIDs recursively
    idval
    idtype
    ts
    conn
    ~conn
  }
  
  flatObjects(func: uid(VAR0)){
    uid
    idval
    idtype
    ts
  }
}

Result

{
  "data": {
    "flatObjects": [
      {
        "uid": "0x4e42",
        "idval": [
          "mygmail.com"
        ],
        "idtype": "gmail",
        "ts": "12313223213"
      },
      {
        "uid": "0x4e43",
        "idval": [
          "uuid2"
        ],
        "idtype": "uuid",
        "ts": "12313223212"
      },
      {
        "uid": "0x4e44",
        "idval": [
          "uuid3"
        ],
        "idtype": "uuid",
        "ts": "12313223212"
      },
      {
        "uid": "0x4e45",
        "idval": [
          "eid"
        ],
        "idtype": "eid",
        "ts": "12313223212"
      },
      {
        "uid": "0x4e46",
        "idval": [
          "fb.com"
        ],
        "idtype": "fb",
        "ts": "12313223212"
      },
      {
        "uid": "0x4e47",
        "idval": [
          "uuid",
          "uuid1"
        ],
        "ts": "12313223211"
      }
    ]
  }
}
1 Like