Skip to content

Commit

Permalink
return error if keywords used as alias in groupby (#3725)
Browse files Browse the repository at this point in the history
  • Loading branch information
balaji authored and mangalaman93 committed Sep 17, 2019
1 parent 6490588 commit 19ed1d1
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 @@ -1983,6 +1983,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 keyword %s as alias in groupby", 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 @@ -3119,6 +3119,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 keyword first as alias in groupby")
}

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

0 comments on commit 19ed1d1

Please sign in to comment.