A subgraph template graph([<path_template1>, <path_template2>, ...])
describes and searches a subgraph model using multiple path templates. These path templates intersect at nodes or edges, which are given aliases in their first appearance in a path template and then called when they appear again.
Statement alias is not supported for the
graph()
command, neither does the statement alias of each path template in thegraph()
command.
Single Relational Alias
Example: as the path structure shown in the graph below, find the customers who received transfer from Customer CU013 and CU016, return with all properties.
graph([
n({_id == "CU013"}).re().n({@card}).re({@transfer}).n({@card} as n).le().n({@customer} as c),
n({_id == "CU016"}).re().n({@card}).re({@transfer}).n(n)
])
return c{*}
Analysis: this subgraph uses Node Alias n to relate the two paths with each other.
Multiple Relational Alias
Example: as the path structure shown in the graph below, find the circular paths: 3 distinct customer's cards perform circular transfer in a single direction, return customers in group.
graph([
n({@customer} as A1).re().n({@card} as C1),
n({@customer && _uuid < A1._uuid} as A2).re().n({@card} as C2),
n({@customer && _uuid < A2._uuid} as A3).re().n({@card} as C3),
n(C1).re().n(C2).re().n(C3).re().n(C1)
])
return A1{*}, A2{*}, A3{*}
Analysis: this subgraph uses Node Alias C1, C2, and C3, to relate 4 paths to each other.
Example: as the path structure shown in the graph below, find bank card information when 2 distinct cards uses the same email addresses, phone numbers, devices, return with all properties.
graph([
n({@card} as C1).e().n({@email}).e().n({@card && _uuid > C1._uuid} as C2),
n(C1 as C11).e().n({@phone}).e().n(C2 as C22),
n(C11).e().n({@device}).e().n(C22)
])
return table(C11._id, C22._id)
Analysis: the subgraph uses Node Alias C1, C2 to relate 3 paths to each other. If an alias is to be referenced for multiple times, it needs to be redefined each time after it is referenced: C1 is redefined as C11, C2 as C22 in the example above.