Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add parser and lexer for upsert block
- Loading branch information
1 parent
6be440b
commit 1ebe573
Showing
6 changed files
with
307 additions
and
39 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package gql | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestMutationTxnBlock1(t *testing.T) { | ||
query := ` | ||
query { | ||
me(func: eq(age, 34)) { | ||
uid | ||
friend { | ||
uid | ||
age | ||
} | ||
} | ||
} | ||
` | ||
_, err := ParseMutation(query) | ||
require.Error(t, err) | ||
require.Contains(t, err.Error(), "Invalid block: [query]") | ||
} | ||
|
||
func TestMutationTxnBlock2(t *testing.T) { | ||
query := ` | ||
upsert { | ||
query { | ||
me(func: eq(age, 34)) { | ||
uid | ||
friend { | ||
uid | ||
age | ||
} | ||
} | ||
} | ||
} | ||
} | ||
` | ||
_, err := ParseMutation(query) | ||
require.Error(t, err) | ||
require.Contains(t, err.Error(), "Too many right curl") | ||
} | ||
|
||
// Is this okay? | ||
// - Doesn't contain mutation op inside Upsert block | ||
// - uid and age are in the same line | ||
func TestMutationTxnBlock3(t *testing.T) { | ||
query := `Upsert{query{me(func:eq(age,34)){uidfriend{uid age}}}}}` | ||
_, err := ParseMutation(query) | ||
require.Error(t, err) | ||
require.Contains(t, err.Error(), "Too many right curl") | ||
} | ||
|
||
func TestMutationTxnBlock4(t *testing.T) { | ||
query := ` | ||
upsert { | ||
query { | ||
me(func: eq(age, 34)) { | ||
uid | ||
friend { | ||
uid | ||
age | ||
} | ||
} | ||
} | ||
mutation { | ||
set { | ||
"_:user1" <age> "45" . | ||
} | ||
} | ||
} | ||
` | ||
_, err := ParseMutation(query) | ||
require.Nil(t, err) | ||
} |
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
Oops, something went wrong.