This is about a behaviour in DGraph that I find kind of unexpected.
When I run a query based on a UID, I always get a JSON result. For example, no node with UID 0x12345 exists and I run this query:
q(func: uid(0x12345)) {
uid
name
email
}
returns something like this:
{
"data": {
"q": [
{
"uid": "0x12345"
}
]
},
"extensions": {
"server_latency": {
"parsing_ns": 81353,
"processing_ns": 350765,
"encoding_ns": 28336,
"assign_timestamp_ns": 492830,
"total_ns": 1017589
...
}
}
This means that my query q
always returns a result list with length greater than 0. Therefore, I cannot use this simple query to check whether a node exists at this UID.
A work around would be:
q(func: has(dgraph.type)) @filter(uid, 0x12345) {
uid
name
email
}
Which would return a query q
with length 0 and thus makes it easy to check whether something exists at the specified UID.
Is this behaviour intentional?
Dgraph metadata
dgraph version
Dgraph version : v21.03.0
Dgraph codename : rocket
Dgraph SHA-256 : b4e4c77011e2938e9da197395dbce91d0c6ebb83d383b190f5b70201836a773f
Commit SHA-1 : a77bbe8ae
Commit timestamp : 2021-04-07 21:36:38 +0530
Branch : HEAD
Go version : go1.16.2
jemalloc enabled : true
For Dgraph official documentation, visit https://dgraph.io/docs.
For discussions about Dgraph , visit http://discuss.dgraph.io.
For fully-managed Dgraph Cloud , visit Products – Dgraph | GraphQL Cloud Platform.
Licensed variously under the Apache Public License 2.0 and Dgraph Community License.
Copyright 2015-2021 Dgraph Labs, Inc.