I am planning my schema and here is something I didn’t understand from the documentation
if I used the @id directive inside an interface, does this enforce uniqueness of that value across all types that use that interface?
Example
interface Named {
name: String! @id @search(by: [hash, regexp])
}
type Person implements Named {
textA: String
textB: String
}
type Company implements Named {
textC: String
textD: String
}
with this given schema Dgraph generates the predicate Named.name type String index/upsert
which is used in both the Type Person and Company
does this prevent me from storing a Person with name Mercedes at the same time as a Company called Mercedes
Hi @jackob, no this doesn’t prevent you from having the same name in Person and Company. Although two different types are inheriting the same interface, there is no link between objects of these two types. You can think of it as two different types that have the same field name.
for completeness to those who stumbled on this thread
if both Person and Company Mercedes exists a call on the interface query like this
query{
getNamed(name: "Mercedes"){
name
}
}
returns data and a helpful error
{
"errors": [
{
"message": "Dgraph returned a list, but getNamed (type Named) was expecting just one item. The first item in the list was used to produce the result.",
"locations": [
{
"line": 2,
"column": 3
}
]
}
],
"data": {
"getNamed": {
"name": "Mercedes"
}
},