@@ -77,6 +77,7 @@ func TestSystem(t *testing.T) {
7777 t .Run ("graphql var child" , wrap (GraphQLVarChild ))
7878 t .Run ("math ge" , wrap (MathGe ))
7979 t .Run ("has should not have deleted edge" , wrap (HasDeletedEdge ))
80+ t .Run ("has should have reverse edges" , wrap (HasReverseEdge ))
8081}
8182
8283func ExpandAllLangTest (t * testing.T , c * dgo.Dgraph ) {
@@ -1523,3 +1524,55 @@ func HasDeletedEdge(t *testing.T, c *dgo.Dgraph) {
15231524 require .Contains (t , ids , uid )
15241525 }
15251526}
1527+
1528+ func HasReverseEdge (t * testing.T , c * dgo.Dgraph ) {
1529+ ctx := context .Background ()
1530+
1531+ check (t , c .Alter (ctx , & api.Operation {
1532+ Schema : `
1533+ follow: uid @reverse .
1534+ ` ,
1535+ }))
1536+ txn := c .NewTxn ()
1537+ defer txn .Discard (ctx )
1538+
1539+ _ , err := txn .Mutate (ctx , & api.Mutation {
1540+ CommitNow : true ,
1541+ SetNquads : []byte (`
1542+ _:alice <name> "alice" .
1543+ _:bob <name> "bob" .
1544+ _:carol <name> "carol" .
1545+ _:alice <follow> _:carol .
1546+ _:bob <follow> _:carol .
1547+ ` ),
1548+ })
1549+ check (t , err )
1550+
1551+ type F struct {
1552+ Name string `json:"name"`
1553+ }
1554+
1555+ txn = c .NewTxn ()
1556+ defer txn .Discard (ctx )
1557+ resp , err := txn .Query (ctx , `{
1558+ fwd(func: has(follow)) { name }
1559+ rev(func: has(~follow)) { name }
1560+ }` )
1561+ check (t , err )
1562+
1563+ t .Logf ("resp: %s\n " , resp .GetJson ())
1564+ m := make (map [string ][]F )
1565+ err = json .Unmarshal (resp .GetJson (), & m )
1566+ check (t , err )
1567+
1568+ fwds := m ["fwd" ]
1569+ revs := m ["rev" ]
1570+
1571+ require .Equal (t , len (fwds ), 2 )
1572+ require .Contains (t , []string {"alice" , "bob" }, fwds [0 ].Name )
1573+ require .Contains (t , []string {"alice" , "bob" }, fwds [1 ].Name )
1574+ require .NotEqual (t , fwds [0 ].Name , fwds [1 ].Name )
1575+
1576+ require .Equal (t , len (revs ), 1 )
1577+ require .Equal (t , revs [0 ].Name , "carol" )
1578+ }
0 commit comments