diff --git a/query/query.go b/query/query.go index ba7dfb407df..bf9d0e00a30 100644 --- a/query/query.go +++ b/query/query.go @@ -2010,6 +2010,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 93877330de3..80cf6ad044e 100644 --- a/query/query1_test.go +++ b/query/query1_test.go @@ -669,6 +669,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 := `