Overview
A path pattern is to match paths in the graph. It is composed of three parts:
- Path Variable Declaration (Optional)
 - Path Pattern Prefix (Optional)
 - Path Pattern Expression
 
<path pattern> ::=
  [ <path variable declaration> ]
  [ <path pattern prefix> ]
  <path pattern expression>
Path Pattern Expression
A path pattern expression (or path pattern for short) defines the nodes and edges that make up a path. Essentially, it is a sequence of node and edge patterns concatenated according to the topological rules of a path - it must start and end with a node and alternate between nodes and edges.
Basic Paths
This path pattern starts from the node Brainy, connecting to a Club node through an outgoing Joins edge:

(:User {name: 'Brainy'})-[:Joins]->(:Club)
You can keep on chaining edge and node patterns to create more complex path patterns. This path pattern describes that Brainy and mochaeach join the same club, with the Club node bound to the variable c:

(:User {name: 'Brainy'})-[:Joins]->(c:Club)<-[:Joins]-(:User {name: 'mochaeach'})
This path pattern reuses the variable a to form a ring-like structure that starts and ends with the same Account node:

(a:Account)-[:Owns]->(:Card)-[:Transfers]->(:Card)-[:Transfers]->(:Card)<-[:Owns]-(a)
Advanced Paths
GQL supports the following advanced path patterns:
Path Variable Declaration
A path variable is declared at the start of a path pattern with =, representing a path binding.
The variable p is bound to paths connecting any two nodes through an outgoing Follows edge:
MATCH p = ()-[:Follows]->()
RETURN p
Path Pattern Prefix
There are two types of path pattern prefixes:
Example Graph

CREATE GRAPH myGraph SHARDS [1]
INSERT (c1:default {_id: 'C1'}),
       (c2:default {_id: 'C2'}),
  	   (c3:default {_id: 'C3'}),
       (c4:default {_id: 'C4'}),
       (c1)-[:default]->(c2),
       (c2)-[:default]->(c1),
       (c2)-[:default]->(c3),
       (c3)-[:default]->(c4)
Path Mode
Path modes control how paths are traversed and whether nodes or edges can be revisited. A path mode may be placed either at the head of a path pattern expression.
Path Mode  | 
Description | 
|---|---|
TRAIL | 
The default. Paths may repeat nodes but not edges. | 
ACYCLIC | 
No repeated nodes are allowed in the paths. | 
SIMPLE | 
No repeated nodes allowed in the paths unless it forms a cycle by starting and ending at the same node. | 
WALK | 
Non-restrictive. | 
The
ACYCLIC,SIMPLE, andWALKare not supported yet.
The following queries find 1- to 3-step outgoing paths from C1 using different path modes:
MATCH p = WALK ({_id: 'C1'})->{1,3}()
RETURN p
MATCH p = ({_id: 'C1'})->{1,3}()
RETURN p
MATCH p = ACYCLIC ({_id: 'C1'})->{1,3}()
RETURN p
MATCH p = SIMPLE ({_id: 'C1'})->{1,3}()
RETURN p
Result: p

Path Selector
A path selector is used to select a limited number of paths from each partition of the match results. When a path pattern matches multiple start and end nodes, the results are conceptually partitioned into distinct pairs of start node and end node. The path selection is performed within each partition, and the result is the union of all paths found for each partition.
| Path Selector | Description | 
|---|---|
ALL | 
      The default. Non-selective. | 
ANY | 
      Selects any one path from each partition. | 
ANY k | 
      Selects any k (non-negative integer) paths from each partition. If a partition has fewer than k paths, all are retained. | 
    
ALL SHORTEST | 
      See Shortest Paths. | 
ANY SHORTEST | 
    |
SHORTEST k | 
    |
SHORTEST k GROUP | 
    
The following queries find 1- to 3-step paths between C1 and target nodes C3 and C4, selecting ALL or ANY paths from each partition:
MATCH p = ({_id: 'C1'})-{1,3}(target WHERE target._id IN ['C3', 'C4'])
RETURN p
MATCH p = ANY ({_id: 'C1'})-{1,3}(target WHERE target._id IN ['C3', 'C4'])
RETURN p
Result: p

Combined Usage
When a query includes both a path selector and a path mode, the path selector should precede the path mode.
To find any 1- to 3-step outgoing WALK paths from C1 (from each partition):
MATCH p = ANY WALK ({_id: 'C1'})->{1,3}()
RETURN p

Special Considerations
Edge Pattern Juxtaposition
Two consecutive edge patterns conceptually have an empty node pattern between them. For example,
(:User)-[]->-[]->(u)
This path term implicitly extends to:
(:User)-[]->()-[]->(u)
A path term should not juxtapose a token that exposes a minus sign on the right (
]-,<-,-) followed by a token that exposes a minus sign on the left (-[,->,-), as this combination introduces the comment symbol--. See Comments.
Node Pattern Juxtaposition
Node pattern juxtaposition is only supported for quantified paths.