Along with some other nodes I‘d like to have a user node. Every user has an username which has to be unique. Is it possible to achieve this in Dgraph?
If you use graphql APIs, the id Directive is directly supported as a schema option to mark uniqueness for fields like username. https://graphql.dgraph.io/doc/schema/ids
I love it.
But can there be multiple unique fields? E.g. Email also has to be unique.
Not supported yet, but in the works. Please see this thread for reference.
Just for me to understand it correctly: In every type there might be up to one “@id”. Am I correct?
Yes, that is correct. You can either use the ID type or the @id directive to establish a unique field.
So if a user has an email address I make a type named email and every email has an address with @id.
This is a workaround but until unique gets available.
Agreed. Cant think of any better or more elegant way to handle this.