Lists

Cypher® lists can be created with Cypher.List passing an array of Cypher expressions. For example:

new Cypher.Return(new Cypher.List([new Cypher.Literal(1), new Cypher.Literal(2)]));
RETURN [1, 2]

It is also possible to include more complex expressions in lists:

new Cypher.List([Cypher.labels(node)]));
RETURN [labels(node)]

Cypher.Literal is a more succinct way of creating simple, literal lists than Cypher.List. You can use instead new Cypher.Literal(["element 1", "element 2"]) to avoid verbose code.

Index

With the .index method of a variable, you can create index access for lists:

myVariable.index(2)
var0[2]

List comprehension

List comprehension can be created with new Cypher.ListComprehension and passing a variable to be used in the comprehension. You also need an expression resulting in the original list to create a new list from:

const listComprehension = new Cypher.ListComprehension(variable, new Cypher.Literal([1,2]))
[var0 IN [1,2]]

Alternatively, the original list expression can be passed with the method .in:

const listComprehension = new Cypher.ListComprehension(variable).in(new Cypher.Literal([1,2]))

By using the methods where and map, you can construct the filter and mapping parts of the comprehension:

const listComprehension = new Cypher.ListComprehension(variable)
    .in(exprVariable)
    .where(andExpr)
    .map(Cypher.plus(variable, new Cypher.Literal(1)));
[var0 IN $param1 WHERE var0 = $param0 | (var0 + 1)]

Pattern comprehension

Pattern comprehension can be created with new Cypher.PatternComprehension, passing a pattern and a map expression, if needed:

const movie = new Cypher.Node();
const rel = new Cypher.Relationship();
const actor=new Cypher.Node()

const pattern = new Cypher.Pattern(movie, { labels: ["Movie"] }).related(rel, { type: "ACTED_IN" }).to(actor, { labels: ["Actor"] })


const comprehension = new Cypher.PatternComprehension(pattern, actor.property("name"));
[(this0:Movie)-[:ACTED_IN]->(this1:Actor) | this1.name]

Filters can be added with the .where method:

const movie = new Cypher.Node();
const rel = new Cypher.Relationship();
const actor = new Cypher.Node();

const pattern = new Cypher.Pattern(movie, { labels: ["Movie"] }).related(rel, { type: "ACTED_IN" }).to(actor, { labels: ["Actor"] });

const comprehension = new Cypher.PatternComprehension(pattern, actor.property("name")).where(
    Cypher.contains(movie.property("title"), new Cypher.Literal("Matrix"))
);
[(this0:Movie)-[this2:ACTED_IN]->(this1:Actor) WHERE this0.title CONTAINS "Matrix" | this1.name]"