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

Throw error when @recurse queries contain nested fields. #3182

Merged
merged 2 commits into from
Mar 21, 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
37 changes: 36 additions & 1 deletion query/query3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,42 @@ func TestRecurseError(t *testing.T) {

_, err := processQuery(t, context.Background(), query)
require.Error(t, err)
require.Contains(t, err.Error(), "Depth must be > 0 when loop is true for recurse query.")
require.Contains(t, err.Error(), "Depth must be > 0 when loop is true for recurse query")
}

func TestRecurseNestedError1(t *testing.T) {
query := `
{
me(func: uid(0x01)) @recurse {
friend {
name
}
name
}
}`

_, err := processQuery(t, context.Background(), query)
require.Error(t, err)
require.Contains(t, err.Error(),
"recurse queries require that all predicates are specified in one level")
}

func TestRecurseNestedError2(t *testing.T) {
query := `
{
me(func: uid(0x01)) @recurse {
friend {
pet {
name
}
}
}
}`

_, err := processQuery(t, context.Background(), query)
require.Error(t, err)
require.Contains(t, err.Error(),
"recurse queries require that all predicates are specified in one level")
}

func TestRecurseQuery(t *testing.T) {
Expand Down
10 changes: 9 additions & 1 deletion query/recurse.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,11 +192,19 @@ func Recurse(ctx context.Context, sg *SubGraph) error {
depth := sg.Params.RecurseArgs.Depth
if depth == 0 {
if sg.Params.RecurseArgs.AllowLoop {
return x.Errorf("Depth must be > 0 when loop is true for recurse query.")
return x.Errorf("Depth must be > 0 when loop is true for recurse query")
}
// If no depth is specified, expand till we reach all leaf nodes
// or we see reach too many nodes.
depth = math.MaxUint64
}

for _, child := range sg.Children {
if len(child.Children) > 0 {
return x.Errorf(
"recurse queries require that all predicates are specified in one level")
}
}

return sg.expandRecurse(ctx, depth)
}