First create a graph table

CREATE GRAPH g
USE GRAPH g

Let's create following nodes and triples

CREATE (Person:john {"firstname":"John"})

CREATE (Person:joe {"firstname":"Joe"})

CREATE (Person:steve {"firstname":"Steve"})

CREATE (Person:sara {"firstname":"Sara"})

CREATE (Person:maria {"firstname":"Maria"})

CREATE (Person:john)-[FRIEND]->(Person:joe)-[FRIEND]->(Person:steve)

CREATE (Person:john)-[FRIEND]->(Person:sara)-[FRIEND]->(Person:maria)

Query which finds a user called 'John' and 'John's' friends (though not his direct friends) before returning both 'John' and any friends-of-friends that are found.

S=>(@p Person:john)-[@f FRIEND]->(@p2 Person:*)-[@f2 FRIEND]->(@p3 Person:*); RETURN p.name AS self, p3.name AS fof
+------+--------+
| self | fof    |
+------+--------+
| john | steve  |
+------+--------+
| john | maria  |
+------+--------+

Query with pattern in the value/field

Next up we will add filtering to set more parts in motion:

We take a list of user names and find all nodes with names from this list, match their friends and return only those followed users who have a 'name' property starting with 'S'.

S=>(@p Person:*)-[@f1 FRIEND]->(@p2 Person:* {name = "s$%"}); RETURN p.name, p2.name
+--------+--------+
| name   | name   |
+--------+--------+
| steve  | steve  |
+--------+--------+
| sara   | sara   |
+--------+--------+