Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only allow one alias per predicate. #4236

Merged
merged 1 commit into from
Nov 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions gql/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -2695,6 +2695,9 @@ func godeep(it *lex.ItemIterator, gq *GraphQuery) error {
return err
}
if peekIt[0].Typ == itemColon {
if len(alias) > 0 {
return item.Errorf("Invalid colon after alias declaration")
}
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 @@ -1646,6 +1646,22 @@ func TestParse_alias1(t *testing.T) {
require.Equal(t, childAttrs(res.Query[0].Children[1]), []string{"type.object.name.hi"})
}

func TestParseBadAlias(t *testing.T) {
query := `
{
me(func: uid(0x0a)) {
name: type.object.name.en: after_colon
bestFriend: friends(first: 10) {
name: type.object.name.hi
}
}
}
`
_, err := Parse(Request{Str: query})
require.Error(t, err)
require.Contains(t, err.Error(), "Invalid colon after alias declaration")
}

func TestParse_block(t *testing.T) {
query := `
{
Expand Down