Documentation Index
Fetch the complete documentation index at: https://gql.ch/llms.txt
Use this file to discover all available pages before exploring further.
CALL statement in GQL invokes a Procedure
For each node find the number of incoming edges
Suppose we are interested in the number of highways flowing into each of the Highway:
We can use the CALL statement to invoke and inline procedure as follows:
MATCH nodes = (b)
CALL {
MATCH path = (a)-[e1:flows_to]->(b)
return path
, count(distinct e1) as incoming_nodes_count
, COLLECT_LIST(distinct a.name) as incoming_nodes
}
return table(b.name, incoming_nodes_count, incoming_nodes)
order by incoming_nodes_count desc;
For each node list paths to all other nodes
We are interested in getting all paths from each to all other nodes:
MATCH nodes = (a)
CALL {
MATCH path = (a)-[edges:flows_to]->{0,}(b)
return reduce(path = a._id, edge in edges | path || '->' || edge._to) as route
, b
}
return table(a.name as starting, b.name as ending, route)
Movie recommendations based on what the 1 degree connection and 2nd degree connection have watched
Recommend movies based on what account 1st and 2nd degree connection have watched:
MATCH friends = ALL (account_a)-[:friends]->{0,2}(account_b)
CALL {
MATCH path = (account_a)-[:watched]->(movie_a)
, (account_b)-[:watched]->(movie_b)
FILTER account_a <> account_b and movie_a <> movie_b
return path
, COLLECT_LIST(distinct movie_a.title) as recommended_movies
}
FILTER account_a <> account_b
return table(account_a.name, account_b.name, recommended_movies);