Skip to content

Commit

Permalink
return error if keywords used as alias
Browse files Browse the repository at this point in the history
Signed-off-by: பாலாஜி ஜின்னா <[email protected]>
  • Loading branch information
பாலாஜி ஜின்னா committed Jul 25, 2019
1 parent cf7c1e6 commit 860dc04
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
3 changes: 3 additions & 0 deletions gql/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -1948,6 +1948,9 @@ func parseGroupby(it *lex.ItemIterator, gq *GraphQuery) error {
if alias != "" {
return item.Errorf("Expected predicate after %s:", alias)
}
if validKey(val) {
return item.Errorf("Can't use %s as alias.", val)
}
alias = val
it.Next() // Consume the itemColon
continue
Expand Down
16 changes: 16 additions & 0 deletions gql/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3021,6 +3021,22 @@ func TestParseGroupbyWithAliasForKey(t *testing.T) {
require.Equal(t, "SchooL", res.Query[0].Children[0].GroupbyAttrs[1].Alias)
}

func TestParseGroupbyWithAliasForError(t *testing.T) {
query := `
query {
me(func: uid(0x1)) {
friends @groupby(first: 10, SchooL: school) {
count(uid)
}
hometown
age
}
}
`
_, err := Parse(Request{Str: query})
require.Contains(t, err.Error(), "Can't use first as alias.")
}

func TestParseGroupbyError(t *testing.T) {
// predicates not allowed inside groupby.
query := `
Expand Down

0 comments on commit 860dc04

Please sign in to comment.