Skip to content

Commit

Permalink
fix(Query): Fix cascade pagination with 0 offset. (#7636)
Browse files Browse the repository at this point in the history
  • Loading branch information
minhaj-shakeel authored and aman-bansal committed Mar 25, 2021
1 parent df7d9f8 commit f091ce5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
7 changes: 4 additions & 3 deletions query/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -1394,7 +1394,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 @@ -2435,7 +2435,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 @@ -2885,7 +2886,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

0 comments on commit f091ce5

Please sign in to comment.