Skip to content

Commit 19ed1d1

Browse files
balajimangalaman93
balaji
authored andcommitted
return error if keywords used as alias in groupby (#3725)
1 parent 6490588 commit 19ed1d1

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

gql/parser.go

+3
Original file line numberDiff line numberDiff line change
@@ -1983,6 +1983,9 @@ func parseGroupby(it *lex.ItemIterator, gq *GraphQuery) error {
19831983
if alias != "" {
19841984
return item.Errorf("Expected predicate after %s:", alias)
19851985
}
1986+
if validKey(val) {
1987+
return item.Errorf("Can't use keyword %s as alias in groupby", val)
1988+
}
19861989
alias = val
19871990
it.Next() // Consume the itemColon
19881991
continue

gql/parser_test.go

+16
Original file line numberDiff line numberDiff line change
@@ -3119,6 +3119,22 @@ func TestParseGroupbyWithAliasForKey(t *testing.T) {
31193119
require.Equal(t, "SchooL", res.Query[0].Children[0].GroupbyAttrs[1].Alias)
31203120
}
31213121

3122+
func TestParseGroupbyWithAliasForError(t *testing.T) {
3123+
query := `
3124+
query {
3125+
me(func: uid(0x1)) {
3126+
friends @groupby(first: 10, SchooL: school) {
3127+
count(uid)
3128+
}
3129+
hometown
3130+
age
3131+
}
3132+
}
3133+
`
3134+
_, err := Parse(Request{Str: query})
3135+
require.Contains(t, err.Error(), "Can't use keyword first as alias in groupby")
3136+
}
3137+
31223138
func TestParseGroupbyError(t *testing.T) {
31233139
// predicates not allowed inside groupby.
31243140
query := `

0 commit comments

Comments
 (0)