Provide unique index support for GraphQL+-

Moved from GitHub dgraph/5512

Posted by sessionboy:

What you wanted to do

I am using GraphQL ±.

I want to achieve a unique index at the database level. I know that GraphQL is planning to support it, but I hope that GraphQL ± will also support it.

I know that the uniqueness can be verified before inserting the record, but I ca n’t guarantee misoperation or someone else inserts the record without verifying the uniqueness. Once this happens it will be extremely bad.

I think like other databases, it is very necessary to achieve uniqueness at the database level。

Like this:

name: string @index(exact) @unique .
username: string @index(exact) @unique .
email: string @unique  .
phone_number: string @unique .

I only need to add a @unique so I don’t need to worry about it anymore, and I can save a lot of extra work.

MichelDiz commented :

Have you tried the upsert block? For those looking for this feature. For now upsert block is the only way to achieve this today.

For more details:

sessionboy commented :

@MichelDiz I want to achieve uniqueness at the database level, which gives me no worries. In fact, this is a basic feature for any database, but dgraph has not implement it.

The upsert block does not solve the problem from the root, it only provides a valid method of inserting records at the API level, but it does not prevent me from using other non-validating methods of inserting records.

GraphQL is planning to support unique, I expect GraphQL ± to be consistent with GraphQL.

1 Like