schema/field: add the Unique option to the UUID field builder (#579)

* add the Unique option to the UUID field builder

* Update schema/field/field_test.go

Co-authored-by: Ariel Mashraki <7413593+a8m@users.noreply.github.com>

Co-authored-by: Ariel Mashraki <7413593+a8m@users.noreply.github.com>
This commit is contained in:
Mohammed Abubakar
2020-07-03 14:31:30 +01:00
committed by GitHub
parent 0ebb0f5e13
commit 902b29d9bf
2 changed files with 8 additions and 0 deletions

View File

@@ -663,6 +663,12 @@ func (b *uuidBuilder) Optional() *uuidBuilder {
return b
}
// Unique makes the field unique within all vertices of this type.
func (b *uuidBuilder) Unique() *uuidBuilder {
b.desc.Unique = true
return b
}
// Immutable indicates that this field cannot be updated.
func (b *uuidBuilder) Immutable() *uuidBuilder {
b.desc.Immutable = true

View File

@@ -342,9 +342,11 @@ func TestField_Enums(t *testing.T) {
func TestField_UUID(t *testing.T) {
fd := field.UUID("id", uuid.UUID{}).
Unique().
Default(uuid.New).
Descriptor()
assert.Equal(t, "id", fd.Name)
assert.True(t, fd.Unique)
assert.Equal(t, "uuid.UUID", fd.Info.String())
assert.Equal(t, "github.com/google/uuid", fd.Info.PkgPath)
assert.NotNil(t, fd.Default)