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

fix(Query): Fix cascade pagination with 0 offset. #7636

Merged
merged 3 commits into from
Mar 23, 2021
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
7 changes: 4 additions & 3 deletions query/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -1380,7 +1380,7 @@ func (sg *SubGraph) populateVarMap(doneVars map[string]varValue, sgPath []*SubGr
child.updateUidMatrix()

// Apply pagination after the @cascade.
if len(child.Params.Cascade.Fields) > 0 && child.Params.Cascade.First != 0 && child.Params.Cascade.Offset != 0 {
if len(child.Params.Cascade.Fields) > 0 && (child.Params.Cascade.First != 0 || child.Params.Cascade.Offset != 0) {
for i := 0; i < len(child.uidMatrix); i++ {
start, end := x.PageRange(child.Params.Cascade.First, child.Params.Cascade.Offset, len(child.uidMatrix[i].Uids))
child.uidMatrix[i].Uids = child.uidMatrix[i].Uids[start:end]
Expand Down Expand Up @@ -2406,7 +2406,8 @@ func (sg *SubGraph) applyOrderAndPagination(ctx context.Context) error {
}
}

if sg.Params.Count == 0 {
// if the @cascade directive is used then retrieve all the results.
if sg.Params.Count == 0 && len(sg.Params.Cascade.Fields) == 0 {
// Only retrieve up to 1000 results by default.
sg.Params.Count = 1000
}
Expand Down Expand Up @@ -2864,7 +2865,7 @@ func (req *Request) ProcessQuery(ctx context.Context) (err error) {
// first time at the root here.

// Apply pagination at the root after @cascade.
if len(sg.Params.Cascade.Fields) > 0 && sg.Params.Cascade.First != 0 && sg.Params.Cascade.Offset != 0 {
if len(sg.Params.Cascade.Fields) > 0 && (sg.Params.Cascade.First != 0 || sg.Params.Cascade.Offset != 0) {
sg.updateUidMatrix()
for i := 0; i < len(sg.uidMatrix); i++ {
start, end := x.PageRange(sg.Params.Cascade.First, sg.Params.Cascade.Offset, len(sg.uidMatrix[i].Uids))
Expand Down
13 changes: 13 additions & 0 deletions query/query0_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,19 @@ func TestCascadeWithPaginationAtRoot(t *testing.T) {
require.JSONEq(t, `{"data":{"me":[{"name":"Andrea","alive":false}]}}`, js)
}

func TestCascadeWithPaginationAndOffsetZero(t *testing.T) {
query := `
{
me(func: type(Person), first: 1, offset: 0) @cascade{
name
alive
}
}
`
js := processQueryNoErr(t, query)
require.JSONEq(t, `{"data":{"me":[{"name":"Rick Grimes","alive":true}]}}`, js)
}

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