Skip to content

Commit 8495323

Browse files
authored
Merge pull request #588 from neo4j/remove-label-operator
Remove labelOperator
2 parents 0fa1d91 + 7c47adb commit 8495323

File tree

15 files changed

+55
-103
lines changed

15 files changed

+55
-103
lines changed

.changeset/easy-horses-repeat.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
---
2+
"@neo4j/cypher-builder": major
3+
---
4+
5+
Remove labelOperator, all labels will now use operator `&`
6+
7+
No longer supported:
8+
9+
```js
10+
const { cypher, params } = matchQuery.build({
11+
labelOperator: "&",
12+
});
13+
```
14+
15+
_Before_
16+
17+
```js
18+
MATCH (this1:Movie:Film)
19+
```
20+
21+
_After_
22+
23+
```cypher
24+
MATCH (this1:Movie&Film)
25+
```

examples/patterns/label-expressions.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,7 @@ const matchQuery = new Cypher.Match(
3030
})
3131
).return(movieNode);
3232

33-
const { cypher, params } = matchQuery.build({
34-
labelOperator: "&",
35-
});
33+
const { cypher, params } = matchQuery.build();
3634

3735
console.log("Cypher");
3836
console.log(cypher);

examples/patterns/length.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,7 @@ const pattern = new Cypher.Pattern(movie).related(actedIn, { type: "ACTED_IN", l
2929

3030
const matchQuery = new Cypher.Match(pattern).return(movie);
3131

32-
const { cypher, params } = matchQuery.build({
33-
labelOperator: "&",
34-
});
32+
const { cypher, params } = matchQuery.build();
3533

3634
console.log("Cypher");
3735
console.log(cypher);

examples/patterns/quantified-path-patterns.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,7 @@ const quantifiedPath = new Cypher.QuantifiedPath(
4141

4242
const query = new Cypher.Match(quantifiedPath).return(m2);
4343

44-
const { cypher, params } = query.build({
45-
labelOperator: "&",
46-
});
44+
const { cypher, params } = query.build();
4745

4846
console.log("Cypher");
4947
console.log(cypher);

src/Environment.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,11 @@ export type EnvPrefix = {
2727
};
2828

2929
export type EnvConfig = {
30-
labelOperator: NonNullable<BuildConfig["labelOperator"]>;
3130
unsafeEscapeOptions: NonNullable<BuildConfig["unsafeEscapeOptions"]>;
3231
cypherVersion: BuildConfig["cypherVersion"];
3332
};
3433

3534
const defaultConfig: EnvConfig = {
36-
labelOperator: ":",
3735
unsafeEscapeOptions: {},
3836
cypherVersion: undefined,
3937
};

src/clauses/Clause.ts

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,6 @@ const customInspectSymbol = Symbol.for("nodejs.util.inspect.custom");
3030
* @group Clauses
3131
*/
3232
export type BuildConfig = Partial<{
33-
/** Defines the default operator for adding multiple labels in a Pattern. Defaults to `":"`
34-
*
35-
* If the target Cypher is version 5 or above, `"&"` is recommended
36-
*
37-
* @example
38-
* `MATCH (this:Movie:Film)`
39-
* `MATCH (this:Movie&Film)`
40-
*
41-
* @deprecated This will be removed in the following major release and the value `"&"` will be used in the generated Cypher
42-
*
43-
*/
44-
labelOperator: ":" | "&";
4533
/** Will prefix generated queries with the Cypher version
4634
* @example `CYPHER 5`
4735
*/
@@ -85,11 +73,10 @@ export abstract class Clause extends CypherASTNode {
8573

8674
/** Compiles a clause into Cypher and params */
8775
public build(config?: BuildConfig): CypherResult {
88-
const { prefix, extraParams = {}, labelOperator = ":", cypherVersion, unsafeEscapeOptions = {} } = config ?? {};
76+
const { prefix, extraParams = {}, cypherVersion, unsafeEscapeOptions = {} } = config ?? {};
8977

9078
if (this.isRoot) {
9179
const env = this.getEnv(prefix, {
92-
labelOperator,
9380
cypherVersion,
9481
unsafeEscapeOptions,
9582
});
@@ -104,7 +91,7 @@ export abstract class Clause extends CypherASTNode {
10491
}
10592
const root = this.getRoot();
10693
if (root instanceof Clause) {
107-
return root.build({ prefix, extraParams, labelOperator, cypherVersion, unsafeEscapeOptions });
94+
return root.build({ prefix, extraParams, cypherVersion, unsafeEscapeOptions });
10895
}
10996
throw new Error(`Cannot build root: ${root.constructor.name}`);
11097
}

src/expressions/HasLabel.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ describe("HasLabel", () => {
5555
const queryResult = new TestClause(query).build();
5656

5757
expect(queryResult.cypher).toMatchInlineSnapshot(`
58-
"MATCH (this0:Movie)
59-
WHERE this0:Movie:Film"
60-
`);
58+
"MATCH (this0:Movie)
59+
WHERE this0:Movie&Film"
60+
`);
6161

6262
expect(queryResult.params).toMatchInlineSnapshot(`{}`);
6363
});

src/expressions/HasLabel.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ export class HasLabel extends CypherASTNode {
5858
private generateLabelExpressionStr(env: CypherEnvironment): string {
5959
if (Array.isArray(this.expectedLabels)) {
6060
const escapedLabels = this.expectedLabels.map((label) => escapeLabel(label));
61-
return addLabelToken(env.config.labelOperator, ...escapedLabels);
61+
return addLabelToken(...escapedLabels);
6262
} else {
63-
return addLabelToken(env.config.labelOperator, this.expectedLabels.getCypher(env));
63+
return addLabelToken(this.expectedLabels.getCypher(env));
6464
}
6565
}
6666

src/pattern/Pattern.test.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -191,9 +191,7 @@ describe("Patterns", () => {
191191
.to(b)
192192
);
193193
const queryResult = query.build();
194-
expect(queryResult.cypher).toMatchInlineSnapshot(
195-
`"(this0:Person:Actor { name: $param0, surname: $param1 })-[this1:ACTED_IN { roles: $param2 }]->(this2)"`
196-
);
194+
expect(queryResult.cypher).toMatchInlineSnapshot(`"(this0:Person&Actor { name: $param0, surname: $param1 })-[this1:ACTED_IN { roles: $param2 }]->(this2)"`);
197195

198196
expect(queryResult.params).toMatchInlineSnapshot(`
199197
{
@@ -225,9 +223,7 @@ describe("Patterns", () => {
225223
.to(b)
226224
);
227225
const queryResult = query.build();
228-
expect(queryResult.cypher).toMatchInlineSnapshot(
229-
`"(this0:Person:Actor)-[this1:ACTED_IN { roles: (\\"The \\" + \\"Matrix\\") }]->(this2)"`
230-
);
226+
expect(queryResult.cypher).toMatchInlineSnapshot(`"(this0:Person&Actor)-[this1:ACTED_IN { roles: (\\"The \\" + \\"Matrix\\") }]->(this2)"`);
231227

232228
expect(queryResult.params).toMatchInlineSnapshot(`{}`);
233229
});

src/pattern/labels-to-string.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ function labelOrTypeToString(
4444
escapeFunc: (s: string) => string
4545
): string {
4646
if (elements instanceof LabelExpr) {
47-
return addLabelToken(env.config.labelOperator, elements.getCypher(env));
47+
return addLabelToken(elements.getCypher(env));
4848
} else {
4949
const escapedLabels = asArray(elements).map((label: string | Expr) => {
5050
if (typeof label === "string") {
@@ -54,6 +54,6 @@ function labelOrTypeToString(
5454
}
5555
});
5656

57-
return addLabelToken(env.config.labelOperator, ...escapedLabels);
57+
return addLabelToken(...escapedLabels);
5858
}
5959
}

0 commit comments

Comments
 (0)