diff --git a/query/query.go b/query/query.go index 355d8644736..10c9434b42e 100644 --- a/query/query.go +++ b/query/query.go @@ -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" { diff --git a/query/query1_test.go b/query/query1_test.go index 9659ae96d86..b448407eee1 100644 --- a/query/query1_test.go +++ b/query/query1_test.go @@ -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 := `