Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set cypherVersionPrefix default value to true #5976

Open
wants to merge 2 commits into
base: 7.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading