You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Mar 29, 2025. It is now read-only.
Copy file name to clipboardExpand all lines: content/graphql/schema/directives/ids.md
+28-3Lines changed: 28 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -13,7 +13,7 @@ Dgraph provides two types of built-in identifiers: the `ID` scalar type and the
13
13
* The `@id` directive is used for external identifiers, such as email addresses.
14
14
15
15
16
-
###The `@id` directive
16
+
## The `@id` directive
17
17
18
18
For some types, you'll need a unique identifier set from outside Dgraph. A common example is a username.
19
19
@@ -63,8 +63,33 @@ query {
63
63
64
64
This will yield a positive response if both the `name`**and**`isbn` match any data in the database.
65
65
66
+
### `@id` and interfaces
66
67
67
-
### Combining `ID` and `@id`
68
+
By default, if used in an interface, the `@id` directive will ensure field uniqueness for each implementing type separately.
69
+
In this case, the `@id` field in the interface won't be unique for the interface but for each of its implementing types.
70
+
This allows two different types implementing the same interface to have the same value for the inherited `@id` field.
71
+
72
+
There are scenarios where this behavior might not be desired, and you may want to constrain the `@id` field to be unique across all the implementing types. In that case, you can set the `interface` argument of the `@id` directive to `true`, and Dgraph will ensure that the field has unique values across all the implementing types of an interface.
73
+
74
+
For example:
75
+
76
+
```graphql
77
+
interfaceItem {
78
+
refID: Int!@id(interface: true) # if there is a Book with refID = 1, then there can't be a chair with that refID.
79
+
itemID: Int!@id # If there is a Book with itemID = 1, there can still be a Chair with the same itemID.
@@ -84,7 +109,7 @@ With this schema, Dgraph requires a unique `username` when creating a new user.
84
109
If in a type there are multiple `@id` fields, then in a `get` query these arguments will be optional. If in a type there's only one field defined with either `@id` or `ID`, then that will be a required field in the `get` query's arguments.
85
110
{{% /notice %}}
86
111
87
-
<!--
112
+
<!--
88
113
### More to come
89
114
90
115
We are currently considering allowing types other than `String` with `@id`, see [here](https://discuss.dgraph.io/t/id-with-type-int/10402)
0 commit comments