There is a question in here, also I plan to add this as a feature request, GitHub mentioned I should write it up here first.
I have a website node that two predicates a websiteUserValue: string
and webProperty: node
.
When creating a website I always want to link to a valid webProperty by passing in the webProperty UID.
Should end up with something like this:
{
"websiteUserValue": "vespertilian",
"webProperty": [
{
"webPropertyName": "Twitter",
"uid": "0x191ab"
}
],
"uid": "0x191b3"
},
When creating a new website if you pass in an invalid webProperty UID, the website still created, no error is thrown it just creates the website without the webPropertyNode
This
{
set {
_:website <websiteUserValue> "Foo" .
_:website <webProperty> <invalidUid> .
}
}
Yields this, no webProperty
{
"websiteUserValue": "test",
"uid": "0x193d5"
},
Question
Currently I am planning on checking that for every website UID that is passed in, the UID points to a node that has a webPropertyName. Is there a better way to do this validation?
Suggestion
It would be nice if I could just tell Dgraph to validate this use case. I am actually using the JSON API not Ratel in my app so I pass in JSON.
I imagine something like this in JSON:
{
websiteUserValue: "vespertilian"
webProperty: {
uid: "0x245"
__validatesPredicates: ["webPropertyName"]
}
}
I have this: “link one specifically structured node to another” pattern multiple places in my app and it would be really helpful to be able to check the validity of the UID as part of the mutation.
Also note you can also pass in a UID to another node and it will link to that node, which for my use case is not ideal.
{
set {
_:website <websiteUserValue> "Foo" .
_:website <webProperty> <someOtherNodeUid> .
}
}