Skip to content

Commit

Permalink
Merge pull request #5976 from neo4j/set-default-cypherVersionPrefix
Browse files Browse the repository at this point in the history
Set cypherVersionPrefix default value to true
  • Loading branch information
angrykoala authored Feb 11, 2025
2 parents bfea7ef + a3a6129 commit d3fa604
Show file tree
Hide file tree
Showing 286 changed files with 2,725 additions and 1,367 deletions.
34 changes: 34 additions & 0 deletions .changeset/kind-clocks-tickle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---
"@neo4j/graphql": major
---

Sets addVersionPrefix to true by default, this will prepend the Cypher version to all queries by default, ensuring that the correct Cypher version is used in Neo4j:

```cypher
CYPHER 5
MATCH(this:Movie)
```

This may be incompatible with older versions of Neo4j and can be disabled by setting `cypherQueryOption.addVersionPrefix` in the context to false:

```js
{
cypherQueryOptions: {
addVersionPrefix: true,
},
}
```

For example, for an apollo server:

```js
await startStandaloneServer(server, {
context: async ({ req }) => ({
req,
cypherQueryOptions: {
addVersionPrefix: false,
},
}),
listen: { port: 4000 },
});
```
3 changes: 2 additions & 1 deletion packages/graphql/src/classes/Executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,8 @@ export class Executor {
}

private getCypherVersionStatement(): string {
if (this.cypherQueryOptions?.addVersionPrefix) {
const addVersionPrefixDefault=true
if (this.cypherQueryOptions?.addVersionPrefix ?? addVersionPrefixDefault) {
return `CYPHER ${SUPPORTED_CYPHER_VERSION}\n`;
}
return "";
Expand Down
5 changes: 3 additions & 2 deletions packages/graphql/src/utils/execute.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ describe("execute", () => {

const tx = {
run: (paramCypher, paramParams) => {
expect(paramCypher).toEqual(cypher);
expect(paramCypher).toBe(`CYPHER 5\n${cypher}`);
expect(paramParams).toEqual(params);

return { records, summary: { counters: { updates: () => ({ test: 1 }) } } };
Expand Down Expand Up @@ -126,7 +126,7 @@ describe("execute", () => {

const tx = {
run: (paramCypher: string, paramParams) => {
expect(trimmer(paramCypher)).toEqual(cypher);
expect(trimmer(paramCypher)).toBe(`CYPHER 5 ${cypher}`);
expect(paramParams).toEqual(params);

return { records, summary: { counters: { updates: () => ({ test: 1 }) } } };
Expand Down Expand Up @@ -189,6 +189,7 @@ describe("execute", () => {
`);

const expectedCypher = trimmer(`
CYPHER 5
CYPHER runtime=interpreted planner=cost updateStrategy=default expressionEngine=compiled operatorEngine=compiled interpretedPipesFallback=all replan=default
CREATE (u:User {title: $title})
RETURN u { .title } as u
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ describe("query options", () => {

const result = await testHelper.executeGraphQL(query, {
variableValues: { id },
contextValue: { cypherQueryOptions: { runtime: "interpreted", addVersionPrefix: true } },
contextValue: { cypherQueryOptions: { runtime: "interpreted", addVersionPrefix: false } },
});

expect(result.errors).toBeFalsy();
Expand Down
90 changes: 60 additions & 30 deletions packages/graphql/tests/tck/advanced-filtering.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ describe("Cypher Advanced Filtering", () => {
const result = await translateQuery(neoSchema, query);

expect(formatCypher(result.cypher)).toMatchInlineSnapshot(`
"MATCH (this:Movie)
"CYPHER 5
MATCH (this:Movie)
WHERE this.title = $param0
RETURN this { .title } AS this"
`);
Expand All @@ -96,7 +97,8 @@ describe("Cypher Advanced Filtering", () => {
const result = await translateQuery(neoSchema, query);

expect(formatCypher(result.cypher)).toMatchInlineSnapshot(`
"MATCH (this:Movie)
"CYPHER 5
MATCH (this:Movie)
WHERE this._id IN $param0
RETURN this { ._id } AS this"
`);
Expand All @@ -122,7 +124,8 @@ describe("Cypher Advanced Filtering", () => {
const result = await translateQuery(neoSchema, query);

expect(formatCypher(result.cypher)).toMatchInlineSnapshot(`
"MATCH (this:Movie)
"CYPHER 5
MATCH (this:Movie)
WHERE this.id =~ $param0
RETURN this { .id } AS this"
`);
Expand All @@ -146,7 +149,8 @@ describe("Cypher Advanced Filtering", () => {
const result = await translateQuery(neoSchema, query);

expect(formatCypher(result.cypher)).toMatchInlineSnapshot(`
"MATCH (this:Movie)
"CYPHER 5
MATCH (this:Movie)
WHERE NOT (this.id = $param0)
RETURN this { .id } AS this"
`);
Expand All @@ -170,7 +174,8 @@ describe("Cypher Advanced Filtering", () => {
const result = await translateQuery(neoSchema, query);

expect(formatCypher(result.cypher)).toMatchInlineSnapshot(`
"MATCH (this:Movie)
"CYPHER 5
MATCH (this:Movie)
WHERE this.id CONTAINS $param0
RETURN this { .id } AS this"
`);
Expand All @@ -194,7 +199,8 @@ describe("Cypher Advanced Filtering", () => {
const result = await translateQuery(neoSchema, query);

expect(formatCypher(result.cypher)).toMatchInlineSnapshot(`
"MATCH (this:Movie)
"CYPHER 5
MATCH (this:Movie)
WHERE this.id STARTS WITH $param0
RETURN this { .id } AS this"
`);
Expand All @@ -218,7 +224,8 @@ describe("Cypher Advanced Filtering", () => {
const result = await translateQuery(neoSchema, query);

expect(formatCypher(result.cypher)).toMatchInlineSnapshot(`
"MATCH (this:Movie)
"CYPHER 5
MATCH (this:Movie)
WHERE this.id ENDS WITH $param0
RETURN this { .id } AS this"
`);
Expand All @@ -242,7 +249,8 @@ describe("Cypher Advanced Filtering", () => {
const result = await translateQuery(neoSchema, query);

expect(formatCypher(result.cypher)).toMatchInlineSnapshot(`
"MATCH (this:Movie)
"CYPHER 5
MATCH (this:Movie)
WHERE this.actorCount < $param0
RETURN this { .actorCount } AS this"
`);
Expand All @@ -269,7 +277,8 @@ describe("Cypher Advanced Filtering", () => {
const result = await translateQuery(neoSchema, query);

expect(formatCypher(result.cypher)).toMatchInlineSnapshot(`
"MATCH (this:Movie)
"CYPHER 5
MATCH (this:Movie)
WHERE this.budget < $param0
RETURN this { .budget } AS this"
`);
Expand All @@ -295,7 +304,8 @@ describe("Cypher Advanced Filtering", () => {

const result = await translateQuery(neoSchema, query);
expect(formatCypher(result.cypher)).toMatchInlineSnapshot(`
"MATCH (this:Movie)
"CYPHER 5
MATCH (this:Movie)
WHERE this.title < $param0
RETURN this { .title } AS this"
`);
Expand All @@ -319,7 +329,8 @@ describe("Cypher Advanced Filtering", () => {
const result = await translateQuery(neoSchema, query);

expect(formatCypher(result.cypher)).toMatchInlineSnapshot(`
"MATCH (this:Movie)
"CYPHER 5
MATCH (this:Movie)
WHERE this.actorCount <= $param0
RETURN this { .actorCount } AS this"
`);
Expand All @@ -346,7 +357,8 @@ describe("Cypher Advanced Filtering", () => {
const result = await translateQuery(neoSchema, query);

expect(formatCypher(result.cypher)).toMatchInlineSnapshot(`
"MATCH (this:Movie)
"CYPHER 5
MATCH (this:Movie)
WHERE this.budget <= $param0
RETURN this { .budget } AS this"
`);
Expand All @@ -372,7 +384,8 @@ describe("Cypher Advanced Filtering", () => {

const result = await translateQuery(neoSchema, query);
expect(formatCypher(result.cypher)).toMatchInlineSnapshot(`
"MATCH (this:Movie)
"CYPHER 5
MATCH (this:Movie)
WHERE this.title <= $param0
RETURN this { .title } AS this"
`);
Expand All @@ -396,7 +409,8 @@ describe("Cypher Advanced Filtering", () => {
const result = await translateQuery(neoSchema, query);

expect(formatCypher(result.cypher)).toMatchInlineSnapshot(`
"MATCH (this:Movie)
"CYPHER 5
MATCH (this:Movie)
WHERE this.actorCount > $param0
RETURN this { .actorCount } AS this"
`);
Expand All @@ -423,7 +437,8 @@ describe("Cypher Advanced Filtering", () => {
const result = await translateQuery(neoSchema, query);

expect(formatCypher(result.cypher)).toMatchInlineSnapshot(`
"MATCH (this:Movie)
"CYPHER 5
MATCH (this:Movie)
WHERE this.budget > $param0
RETURN this { .budget } AS this"
`);
Expand All @@ -449,7 +464,8 @@ describe("Cypher Advanced Filtering", () => {

const result = await translateQuery(neoSchema, query);
expect(formatCypher(result.cypher)).toMatchInlineSnapshot(`
"MATCH (this:Movie)
"CYPHER 5
MATCH (this:Movie)
WHERE this.title > $param0
RETURN this { .title } AS this"
`);
Expand All @@ -473,7 +489,8 @@ describe("Cypher Advanced Filtering", () => {
const result = await translateQuery(neoSchema, query);

expect(formatCypher(result.cypher)).toMatchInlineSnapshot(`
"MATCH (this:Movie)
"CYPHER 5
MATCH (this:Movie)
WHERE this.actorCount >= $param0
RETURN this { .actorCount } AS this"
`);
Expand All @@ -500,7 +517,8 @@ describe("Cypher Advanced Filtering", () => {
const result = await translateQuery(neoSchema, query);

expect(formatCypher(result.cypher)).toMatchInlineSnapshot(`
"MATCH (this:Movie)
"CYPHER 5
MATCH (this:Movie)
WHERE this.budget >= $param0
RETURN this { .budget } AS this"
`);
Expand All @@ -526,7 +544,8 @@ describe("Cypher Advanced Filtering", () => {

const result = await translateQuery(neoSchema, query);
expect(formatCypher(result.cypher)).toMatchInlineSnapshot(`
"MATCH (this:Movie)
"CYPHER 5
MATCH (this:Movie)
WHERE this.title >= $param0
RETURN this { .title } AS this"
`);
Expand All @@ -551,7 +570,8 @@ describe("Cypher Advanced Filtering", () => {
const result = await translateQuery(neoSchema, query);

expect(formatCypher(result.cypher)).toMatchInlineSnapshot(`
"MATCH (this:Movie)
"CYPHER 5
MATCH (this:Movie)
WHERE EXISTS {
MATCH (this)-[:IN_GENRE]->(this0:Genre)
WHERE this0.name = $param0
Expand Down Expand Up @@ -583,7 +603,8 @@ describe("Cypher Advanced Filtering", () => {
const result = await translateQuery(neoSchema, query);

expect(formatCypher(result.cypher)).toMatchInlineSnapshot(`
"MATCH (this:Movie)
"CYPHER 5
MATCH (this:Movie)
WHERE (EXISTS {
MATCH (this)-[:IN_GENRE]->(this0:Genre)
WHERE this0.name = $param0
Expand All @@ -606,7 +627,8 @@ describe("Cypher Advanced Filtering", () => {
const result = await translateQuery(neoSchema, query);

expect(formatCypher(result.cypher)).toMatchInlineSnapshot(`
"MATCH (this:Movie)
"CYPHER 5
MATCH (this:Movie)
WHERE NOT (EXISTS {
MATCH (this)-[:IN_GENRE]->(this0:Genre)
WHERE this0.name = $param0
Expand All @@ -626,7 +648,8 @@ describe("Cypher Advanced Filtering", () => {
const result = await translateQuery(neoSchema, query);

expect(formatCypher(result.cypher)).toMatchInlineSnapshot(`
"MATCH (this:Movie)
"CYPHER 5
MATCH (this:Movie)
WHERE single(this0 IN [(this)-[:IN_GENRE]->(this0:Genre) WHERE this0.name = $param0 | 1] WHERE true)
RETURN this { .actorCount } AS this"
`);
Expand All @@ -642,7 +665,8 @@ describe("Cypher Advanced Filtering", () => {
const result = await translateQuery(neoSchema, query);

expect(formatCypher(result.cypher)).toMatchInlineSnapshot(`
"MATCH (this:Movie)
"CYPHER 5
MATCH (this:Movie)
WHERE EXISTS {
MATCH (this)-[:IN_GENRE]->(this0:Genre)
WHERE this0.name = $param0
Expand Down Expand Up @@ -671,7 +695,8 @@ describe("Cypher Advanced Filtering", () => {
const result = await translateQuery(neoSchema, query);

expect(formatCypher(result.cypher)).toMatchInlineSnapshot(`
"MATCH (this:Movie)
"CYPHER 5
MATCH (this:Movie)
WHERE EXISTS {
MATCH (this)-[this0:IN_GENRE]->(this1:Genre)
WHERE this1.name = $param0
Expand All @@ -698,7 +723,8 @@ describe("Cypher Advanced Filtering", () => {
const result = await translateQuery(neoSchema, query);

expect(formatCypher(result.cypher)).toMatchInlineSnapshot(`
"MATCH (this:Movie)
"CYPHER 5
MATCH (this:Movie)
WHERE NOT (EXISTS {
MATCH (this)-[this0:IN_GENRE]->(this1:Genre)
WHERE this1.name = $param0
Expand Down Expand Up @@ -730,7 +756,8 @@ describe("Cypher Advanced Filtering", () => {
const result = await translateQuery(neoSchema, query);

expect(formatCypher(result.cypher)).toMatchInlineSnapshot(`
"MATCH (this:Movie)
"CYPHER 5
MATCH (this:Movie)
WHERE (EXISTS {
MATCH (this)-[this0:IN_GENRE]->(this1:Genre)
WHERE this1.name = $param0
Expand All @@ -752,7 +779,8 @@ describe("Cypher Advanced Filtering", () => {
const result = await translateQuery(neoSchema, query);

expect(formatCypher(result.cypher)).toMatchInlineSnapshot(`
"MATCH (this:Movie)
"CYPHER 5
MATCH (this:Movie)
WHERE NOT (EXISTS {
MATCH (this)-[this0:IN_GENRE]->(this1:Genre)
WHERE this1.name = $param0
Expand All @@ -771,7 +799,8 @@ describe("Cypher Advanced Filtering", () => {
const result = await translateQuery(neoSchema, query);

expect(formatCypher(result.cypher)).toMatchInlineSnapshot(`
"MATCH (this:Movie)
"CYPHER 5
MATCH (this:Movie)
WHERE single(this0 IN [(this)-[this1:IN_GENRE]->(this0:Genre) WHERE this0.name = $param0 | 1] WHERE true)
RETURN this { .actorCount } AS this"
`);
Expand All @@ -787,7 +816,8 @@ describe("Cypher Advanced Filtering", () => {
const result = await translateQuery(neoSchema, query);

expect(formatCypher(result.cypher)).toMatchInlineSnapshot(`
"MATCH (this:Movie)
"CYPHER 5
MATCH (this:Movie)
WHERE EXISTS {
MATCH (this)-[this0:IN_GENRE]->(this1:Genre)
WHERE this1.name = $param0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ describe("Cypher Aggregations Many with Alias directive", () => {
const result = await translateQuery(neoSchema, query);

expect(formatCypher(result.cypher)).toMatchInlineSnapshot(`
"CALL {
"CYPHER 5
CALL {
MATCH (this:Movie)
WITH this
ORDER BY size(this._title) DESC
Expand Down
3 changes: 2 additions & 1 deletion packages/graphql/tests/tck/aggregations/alias.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ describe("Cypher Aggregations Many while Alias fields", () => {
const result = await translateQuery(neoSchema, query);

expect(formatCypher(result.cypher)).toMatchInlineSnapshot(`
"CALL {
"CYPHER 5
CALL {
MATCH (this:Movie)
RETURN count(this) AS var0
}
Expand Down
Loading

0 comments on commit d3fa604

Please sign in to comment.