diff --git a/gql/parser.go b/gql/parser.go index 9ca947386c0..f7d0d55ac59 100644 --- a/gql/parser.go +++ b/gql/parser.go @@ -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 diff --git a/gql/parser_test.go b/gql/parser_test.go index a51fd64f655..592bdeb8111 100644 --- a/gql/parser_test.go +++ b/gql/parser_test.go @@ -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 := `