We’ll take this onboard as we look at GraphQL features. No commitment yet on what we’ll support, but it would be great to support composite keys as well as the kind of uniqueness described here.
Hi @Wulfheart, this request is definitely in our roadmap and the team has plans to work on it. This can be seen in the docs too at the bottom of GraphQL docs.
Hi. Nice to see this on the radar. I am interested in this as well. It would be great to have not just IDs but also composite unique constraints like unique (col1, col2) Thanks
Hi @vinniefg, thanks for showing interest in this feature.
Sorry, this won’t be part of the next 20.11 release. But this is definitely under consideration for later and maybe prioritized based on demands. I can’t give you any ETA though.
Thanks.
Does the unique field will also support unique constraint based on the filtering on a given field ? For example, if we want to have unique label names per company, we could say
Hi @dtrckd, as of now we are just allowing the @id field to be applied on multiple field in a type and every field with @id directive will be unique over the nodes of that type.
RFC: RFC: Allow multiple unique fields in graphql schema
@rajas I just wanted to give an example of a perfect use case for this. While you are building graphql facets, there is a need for this in basic graphs.
Let’s say a user reviews a movie, there should be only one review:
Obviously, it would be better to have a unique restraint like in SQL:
ALTER TABLE `Rating` ADD UNIQUE `unique_index`(`user`, `movie`);
Hi @jdgamble555, multiple @id fields doesn’t guarantee unique constrain on a combination of two fields.
It just means that we can have multiple @id fields in a type. And every such field value will be unique across all the nodes of that type. But other @id fields or normal fields in a type can have that value.
Example :
type {
t1: String @id
t2: String @id
t3: string
}
Below is the valid state according to @id rules but it doesn’t guarantee unique constraint on two fields.
node1:-
t1-“Alice”
t2-“Bob”
Hi @rajatjindal , Welcome to the Dgraph community !! @id is a graphql concept and works only in graphql layer. You posted a Graphql schema but the given mutation is of type DQL(Dgraph query language) and is on dgraph endpoint. http://localhost:8080/query —DQL query endpoint http://localhost:8080/mutate --DQL mutation endpoint