Querying for nodes connected to a particular node

Using the IMDB dataset example, suppose we have to find out all the persons connected to the movie “The Princess Bride”. The persons may be connected to the movie “The Princess Bride” node by different edges like the actor, director etc.
We can write the query in cypher like:

MATCH (p:Person)–>(m:movie { title: ‘The Princess Bride’ })
RETURN p.name

How we can write the same query in Dgraph?

{
  q(func: type(Person)) @filter(eq(name, "Devin Townsend")) @cascade {
    name
    movie @filter(eq(name, "Devin Townsend"))
  }
}

But I’m not sure about this neo4j query. It doesn’t have and specified edge. So in Dgraph that could mean a recurse query.

{
  q(func: type(Person)) @filter(eq(name, "Devin Townsend")) @cascade @recurse {
    name
    movie @filter(eq(name, "Devin Townsend")) #One of these gonna be true
    film @filter(eq(name, "The Princess Bride’"))
    liked @filter(eq(name, "The Princess Bride’"))
    watched @filter(eq(name, "The Princess Bride’"))
    rated @filter(eq(name, "The Princess Bride’"))
  }
}

In Dgraph you need to specify the edge.

Cheers.

Thanks @MichelDiz for clarifying my doubts. In RedisGraph or Neo4j we can do that without specifying the edge name. (p:Person)–>(m:movie { title: ‘The Princess Bride’ }) this returns all the Person nodes which are connected to the movie node with title: ‘The Princess Bride’ by any edge. That’s why I was confused whether Dgraph also has the same functionality.

Yep, you can fill up an issue for this. I think there’s none about it. But make sure.

For now, you can do like as I exemplified.

I believe expand func would be something to use as an analog to this feature. e.g.

{
  q(func: type(Person)) @filter(eq(name, "Devin Townsend")) @cascade {
    name
    expand(_edges_) @filter(eq(name, "The Princess Bride’")) 
  }
}

Similar to the recent deprecated expand(_forward_) and expand(_reverse_).

1 Like