Support multiple unique fields in dgraph GraphQL

Moved from GitHub dgraph/5232

Posted by sessionboy:

What you wanted to do

Expect team to provide support for multiple unique fields in dgraph GraphQL, this is a very common requirement, like this:

 type User {
    id: ID!
    name: String! @unique
    username: String! @unique
    phone_number: String! @unique
    email: String @unique
    ...
 }

The unique field is allowed to be empty, and no verification is performed when the value of the unique field is empty. For example email above.

Any external references to support your case

prisma provides a great implementation for this, which can be used as a reference.

5 Likes

MichaelJCompton commented :

Hi, thanks for the suggestion.

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.

2 Likes

sessionboy commented :

Thanks for team efforts, I look forward to it.

Any update on this?

1 Like

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. :slight_smile:

5 Likes

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

2 Likes

Is there an ETA yet?

1 Like

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.

2 Likes

+1 on this feature. Hopefully this gets implemented by the team soon.

3 Likes

Also +1 on this feature. Feels like a basic thing to have.

1 Like

Hi, +1 for this feature.

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

type Label {
  name: String! @unique(f: "company") 
  company:  String! @search
}
1 Like

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: [WIP]RFC: Allow multiple unique fields in graphql schema

1 Like

When you say “as of now,” what version of dgraph is “now?”

Hi @oising,

Welcome to Dgraph Community !!

Multiple ID fields feature is in planning stage and is not available in any Dgraph versions. The related RFC is [WIP]RFC: Allow multiple unique fields in graphql schema .

The “as of now” refers to what is being considered in RFC and does not refer to any existing Dgraph version.

If you want to to know the latest version of Dgraph, it is 20.11 . You may find more details here, Release Notes v20.11.0 - Tenacious T'Challa .

1 Like