-
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 parser and lexer for mutation using txn block
- Loading branch information
1 parent
6be440b
commit d936cba
Showing
6 changed files
with
288 additions
and
32 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 := ` | ||
txn { | ||
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 txn block | ||
// - uid and age are in the same line | ||
func TestMutationTxnBlock3(t *testing.T) { | ||
query := `txn{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 := ` | ||
txn { | ||
mutation { | ||
set { | ||
"_:user1" <age> "45" . | ||
} | ||
} | ||
query { | ||
me(func: eq(age, 34)) { | ||
uid | ||
friend { | ||
uid | ||
age | ||
} | ||
} | ||
} | ||
} | ||
` | ||
_, 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.