Documentation: Matching closed paths/cycles

Moved from GitHub dgraph/4417

Posted by imkleats:

Documentation

GraphQL+/- provides a very intuitive way to interface with a connected, acyclic graph (AKA trees). However, it isn’t apparent how to deal with cyclical patterns (matching any path that starts and ends on the same node). Additional documentation of how to match closed paths is warranted.

This issue comes from a post on the Discuss forum: Problem about nodes filter according to an edge
The question being posed is about how to query forum posts that fit in the following closed pattern:

match (f:Forum)-[hasMember {year > 4}]->(:Person)<-[hasCreator]-(p:Post)<-[containerOf]-(f)
return p

I’ve flagged this as a Documentation issue on the chance that Dgraph folks either know or can figure out a way to accomplish generalized cyclical pattern-matching using currently available methods. However, from my initial exploration, it is unclear whether the way UIDs are collected in var blocks even currently support modeling cyclical patterns; the following approach does not appear work:

eachGivenForum as var(type(forum)) @cascade {
  hasMember @facets(gt(year,4)) {
    matchingPosts as ~hasCreator {
      ~containerOf @filter(uid(eachGivenForum)) { # trying to filter to each indiv. Forum uid
        uid                                       # this block is being evaluated for
      }
    }
  }
}

q(func: uid(matchingPosts)) { ... }

Being able to model and match cyclical patterns in a generalizable way is pretty important, so hopefully this can be resolved.