# Uniqueness for @id fields on interface

**URL:** <https://discuss.dgraph.io/t/uniqueness-for-id-fields-on-interface/13294>\
**Category:** GraphQL\
**Tags:** kind:enhancement, status:accepted, ticket:created\
**Created:** [March 18, 2021, 10:12am UTC](https://discuss.dgraph.io/t/uniqueness-for-id-fields-on-interface/13294 "2021-03-18T10:12:22Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![christiansmith](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/christiansmith/32/7273_2.png) [@christiansmith](https://discuss.dgraph.io/u/christiansmith)\
**Post date:** [March 18, 2021, 10:12am UTC](https://discuss.dgraph.io/t/uniqueness-for-id-fields-on-interface/13294/1 "2021-03-18T10:12:22Z")

</div>

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:

```auto
interface Profile {
  name: String! @id @unique
  about: String
}

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

```

---

<div class="post-metadata">

**Author:** ![JatinDevDG](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/jatindevdg/32/3417_2.png) [@JatinDevDG](https://discuss.dgraph.io/u/JatinDevDG)\
**Post date:** [March 18, 2021, 4:05pm UTC](https://discuss.dgraph.io/t/uniqueness-for-id-fields-on-interface/13294/2 "2021-03-18T16:05:36Z")

</div>

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

```auto
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 !!

---

<div class="post-metadata">

**Author:** ![christiansmith](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/christiansmith/32/7273_2.png) [@christiansmith](https://discuss.dgraph.io/u/christiansmith)\
**Post date:** [March 21, 2021, 6:42pm UTC](https://discuss.dgraph.io/t/uniqueness-for-id-fields-on-interface/13294/3 "2021-03-21T18:42:15Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![JatinDevDG](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/jatindevdg/32/3417_2.png) [@JatinDevDG](https://discuss.dgraph.io/u/JatinDevDG)\
**Post date:** [April 7, 2021, 9:13am UTC](https://discuss.dgraph.io/t/uniqueness-for-id-fields-on-interface/13294/5 "2021-04-07T09:13:02Z")

</div>

A post was split to a new topic: [Multiple ID issue](https://discuss.dgraph.io/t/multiple-id-issue/13575)

---

<div class="post-metadata">

**Author:** ![JatinDevDG](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/jatindevdg/32/3417_2.png) [@JatinDevDG](https://discuss.dgraph.io/u/JatinDevDG)\
**Post date:** [April 7, 2021, 9:17am UTC](https://discuss.dgraph.io/t/uniqueness-for-id-fields-on-interface/13294/6 "2021-04-07T09:17:48Z")

</div>

A post was merged into an existing topic: [Multiple ID issue](https://discuss.dgraph.io/t/multiple-id-issue/13575/2)

---

<div class="post-metadata">

**Author:** ![JatinDevDG](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/jatindevdg/32/3417_2.png) [@JatinDevDG](https://discuss.dgraph.io/u/JatinDevDG)\
**Post date:** [April 17, 2021, 9:22pm UTC](https://discuss.dgraph.io/t/uniqueness-for-id-fields-on-interface/13294/7 "2021-04-17T21:22:00Z")

</div>

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](https://github.com/dgraph-io/dgraph/pull/7710)
