Skip to content

Commit

Permalink
Merge 07ec9af into 69481ed
Browse files Browse the repository at this point in the history
  • Loading branch information
wildan2711 committed Jan 14, 2021
2 parents 69481ed + 07ec9af commit d962eba
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
2 changes: 1 addition & 1 deletion mutate.go
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ func parseQueryIndex(queryIndex string) (id string, schemaIndex int, err error)
}

id = queryIndexParts[1]
isAlias := !(isUID(id) && isUIDFunc(id))
isAlias := !(isUID(id) || isUIDFunc(id))
if isAlias {
id = "_:" + id
}
Expand Down
43 changes: 43 additions & 0 deletions mutate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,49 @@ func TestMutationMutate(t *testing.T) {
assert.IsType(t, &UniqueError{}, err, err.Error())
}

func TestMutationMutate_UpdateUnique(t *testing.T) {
c := newDgraphClient()

_, err := CreateSchema(c, TestUser{})
if err != nil {
t.Error(err)
}
defer dropAll(c)

tx := NewTxn(c).SetCommitNow()
users := []TestUser{
{
Name: "supa saiyan",
Username: "myuser",
Email: "myemail@gmail.com",
},
{
Name: "supa saiyan",
Username: "myuser1",
Email: "myemail1@gmail.com",
},
}

uids, err := tx.Mutate(&users)
if err != nil {
t.Error(err)
}

assert.Len(t, uids, 2)

tx = NewTxn(c).SetCommitNow()
user := TestUser{
UID: users[0].UID,
Name: "new name",
Username: users[1].Username,
Email: "newemail@gmail.com",
}

uids, err = tx.Mutate(&user)
assert.Len(t, uids, 0)
assert.IsType(t, &UniqueError{}, err, err.Error())
}

func TestMutationMutate_SetEdge(t *testing.T) {
c := newDgraphClient()

Expand Down

0 comments on commit d962eba

Please sign in to comment.