@unique
Specifies the name of a Fauna index that enforces a uniqueness constraint.
Description
The @unique
directive marks a field as being unique. Unique fields
have an associated unique index within the database. The index
argument controls the name of the unique index. By default, the index
name uses this template: unique_<type name>_<field name>
.
Example
When the following GraphQL schema has been imported:
type User {
name: String! @unique(index: "unique_username")
}
The database contains the following index:
Get(Index("unique_username"))
{ ref: Index("unique_username"),
ts: 1560525943310000,
active: true,
partitions: 1,
name: 'unique_username',
source: Collection("User"),
data: { gql: { ts: Time("2019-06-14T15:25:43.226352Z") } },
terms: [ { field: [ 'data', 'name' ] } ],
unique: true }
Is this article helpful?
Tell Fauna how the article can be improved:
Visit Fauna's forums
or email docs@fauna.com
Thank you for your feedback!