-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for Conditional Upsert (#3612)
- Loading branch information
1 parent
ec3cb29
commit 1cf7bfa
Showing
7 changed files
with
360 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,9 +21,8 @@ import ( | |
"sync" | ||
"testing" | ||
|
||
"github.com/dgraph-io/dgraph/testutil" | ||
|
||
"github.com/dgraph-io/dgo/y" | ||
"github.com/dgraph-io/dgraph/testutil" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
|
@@ -794,3 +793,68 @@ upsert { | |
_, _, _, err := mutationWithTs(m, "application/rdf", false, true, true, 0) | ||
require.NoError(t, err) | ||
} | ||
|
||
func TestConditionalUpsertExample0(t *testing.T) { | ||
require.NoError(t, dropAll()) | ||
require.NoError(t, alterSchema(`email: string @index(exact) .`)) | ||
|
||
// Mutation with wrong name | ||
m1 := ` | ||
upsert { | ||
mutation { | ||
set { | ||
uid(v) <name> "Wrong" . | ||
uid(v) <email> "[email protected]" . | ||
} | ||
} | ||
query { | ||
me(func: eq(email, "[email protected]")) { | ||
v as uid | ||
} | ||
} | ||
}` | ||
keys, preds, _, err := mutationWithTs(m1, "application/rdf", false, true, true, 0) | ||
require.NoError(t, err) | ||
require.True(t, len(keys) == 0) | ||
require.True(t, contains(preds, "email")) | ||
require.True(t, contains(preds, "name")) | ||
|
||
// query should return the wrong name | ||
q1 := ` | ||
{ | ||
q(func: has(email)) { | ||
uid | ||
name | ||
} | ||
}` | ||
res, _, err := queryWithTs(q1, "application/graphql+-", "", 0) | ||
require.NoError(t, err) | ||
require.Contains(t, res, "Wrong") | ||
|
||
// mutation with correct name | ||
m2 := ` | ||
upsert { | ||
mutation @if(eq(len(v), 1)) { | ||
set { | ||
uid(v) <name> "Ashish" . | ||
} | ||
} | ||
query { | ||
me(func: eq(email, "[email protected]")) { | ||
v as uid | ||
} | ||
} | ||
}` | ||
keys, preds, _, err = mutationWithTs(m2, "application/rdf", false, true, true, 0) | ||
require.NoError(t, err) | ||
require.True(t, len(keys) == 0) | ||
require.True(t, contains(preds, "name")) | ||
|
||
// query should return correct name | ||
res, _, err = queryWithTs(q1, "application/graphql+-", "", 0) | ||
require.NoError(t, err) | ||
require.Contains(t, res, "Ashish") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.