Fetching a non-existent node returns the fetched uid rather than an empty result


(Yasha Prikhodko) #1

When I query for a non-existent node like so:

{
  something(func: uid(0x10000524)) {
    uid
    name
  }
}

It returns the uid I requested for even though the node does not exist:

{
  "data": {
    "something": [
      {
        "uid": "0x10000524"
      }
    ]
  },
  "extensions": {
    "server_latency": {
      "parsing_ns": 13144,
      "processing_ns": 14520675,
      "encoding_ns": 816140
    },
    "txn": {
      "start_ts": 150008
    }
  }
}

However, if I query without the uid (but I need it, so i cannot simply drop it):

{
  something(func: uid(0x10000524)) {
    name
  }
}

I get the result i would expect if a node is not found:

{
  "data": {
    "something": []
  },
  "extensions": {
    "server_latency": {
      "parsing_ns": 35725,
      "processing_ns": 10055340,
      "encoding_ns": 1167598
    },
    "txn": {
      "start_ts": 150040
    }
  }
}

I was told that this is an intended behaviour and that I simply shouldn’t be querying the uid if I want an empty result when querying for a non-existent node. What’s the logic behind this?

Thank you!
Yasha.


(Daniel Mai) #2

Treat the uid() function as an identity function. Whatever uid you provide will give you back that same uid.