There are two misleading things that happen when using the uid() func in certain scenarios:
- When the UID is malformed (i.e. doesn’t follow the ‘0x123abc’ format), it returns the error “Some variables are used but not defined”.
query getNode {
someNode(func: uid(bad-uid) {
uid
}
}
→
Error: 2 UNKNOWN: Some variables are used but not defined
Defined:[]
Used:[bad-uid]
- When querying for a node with a UID that does not exist, the query returns a node with that UID
{
someNode(func: uid(0x9999999)) {
uid
name
}
}
→
"data": {
"someNode": [
{
"uid": "0x9999999"
}
]
}
In both of these cases, I’d expect some kind of “Node does not exist” error.
For the first scenario, I can always validate the UID before making the query. Do UIDs always start with 0x
?
For the second - what’s the best way to handle this?