Uniqueness for @id fields on interface

This change broke our app yesterday when Slash upgraded because getInterface() suddenly disappeared, which we’re relying on in several places. It’s not that big of an inconvenience to switch to queryInterface(), but there’s a bigger problem.

We have a handful of situations where we want to enforce uniqueness of @id across all types of an interface. For example, we use @id in urls where the routing is something like https://app.tld/@id and @id could refer to any of number of types, which we then render according to __typename.

Of course we can try to enforce in our application that nodes with conflicting @id are not created but it would be infinitely better if we could declare a property to be @unique within the interface:

interface Profile {
  name: String! @id @unique
  about: String

type Person implements Profile { ... }
type Team implements Profile { ... }

Hi @christiansmith, Welcome to the Dgraph community!!

We basically had this issue in getQuery when multiple implementations of interface uses @id field and if they have same value for that field then getQuery return error because @id fields are not unique across implementation types. So we decided to remove the @id field argument from getQuery on interfaces.

But as many users having problem with this braking change , we are now supporting it till 21.11.0 release (which will happen in November December this year) and till then mark it as deprecated in the generated schema to give users time to update their query.

We have also discussed your proposal to have @unique directive in interfaces with @id directive.
It seems like a good feature and we are thinking of having it. So, the final behaviour would be something like this

interface Profile {
  nameGlobal : String! @id @unique // This field will be unique across implementing types of interface and will be available in argument to getQuery on interface.
  nameLocal:  String! @id   //This field will be unique only in the implementing types and won't be added  in argument to getQuery on interface. 
  about: String

So, if you are only using @id field inside the interface and need that field inside getQuery for interface then , you will have to add @unique directive on it in future(after 21.11.0).
This is just a initial design and it may change a bit, but yeah we are looking forward to add something similar. Thanks !!


This is great to hear. Thanks to all for your consideration and hard work.

1 Like

A post was split to a new topic: Multiple ID issue

A post was merged into an existing topic: Multiple ID issue

This feature is implemented in master branch and will be available in 21.07 release.

PR: Feat(GraphQL): This PR allows @id field in interface to be unique across all the implementing types. by JatinDevDG · Pull Request #7710 · dgraph-io/dgraph · GitHub

1 Like