Skip to content

Commit

Permalink
Pagination param "after" does not work when using func: uid(v) (#6365)
Browse files Browse the repository at this point in the history
fixed : Pagination param "after" does not work when using func: uid(v)
(cherry picked from commit 732732b)
  • Loading branch information
antblood authored and Neeraj Battan committed Oct 2, 2020
1 parent 7eac316 commit 70fd76f
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
5 changes: 5 additions & 0 deletions query/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -1982,6 +1982,11 @@ func ProcessGraph(ctx context.Context, sg, parent *SubGraph, rch chan error) {
return sg.DestUIDs.Uids[i] < sg.DestUIDs.Uids[j]
})
}
if sg.Params.AfterUID > 0 {
i := sort.Search(len(sg.DestUIDs.Uids), func(i int) bool { return sg.DestUIDs.Uids[i] > sg.Params.AfterUID })
sg.DestUIDs.Uids = sg.DestUIDs.Uids[i:]
}

case sg.Attr == "":
// This is when we have uid function in children.
if sg.SrcFunc != nil && sg.SrcFunc.Name == "uid" {
Expand Down
37 changes: 37 additions & 0 deletions query/query1_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -668,6 +668,43 @@ func TestHasFuncAtRootWithAfter(t *testing.T) {
require.JSONEq(t, `{"data": {"me":[{"friend":[{"count":1}],"name":"Rick Grimes","uid":"0x17"},{"friend":[{"count":1}],"name":"Andrea","uid":"0x1f"}]}}`, js)
}

func TestHasFuncAtRootWithAfterOnUIDs(t *testing.T) {

query := `
{
var(func: has(name)) {
uids as uid
}
me(func: uid(uids), first: 2, after: 0x5) {
uid
}
}
`

js := processQueryNoErr(t, query)
require.JSONEq(t, `{"data": {"me":[{"uid":"0x6"},{"uid":"0x7"}]}}`, js)
}

func TestHasFuncAtRootWithAfterOnUIDsOtherThanRoot(t *testing.T) {

query := `
{
var(func: has(name)) {
uids as uid
}
me(func: uid(0x1, 0x1f)) {
uid
friend(first:2, after:0x5) @filter(uid(uids)) {
uid
}
}
}
`

js := processQueryNoErr(t, query)
require.JSONEq(t, `{"data": {"me":[{"uid":"0x1","friend":[{"uid": "0x17"},{"uid": "0x18"}]},{"uid": "0x1f","friend": [{"uid": "0x18"}]}]}}`, js)
}

func TestHasFuncAtRootFilter(t *testing.T) {

query := `
Expand Down

0 comments on commit 70fd76f

Please sign in to comment.