Skip to content

Commit

Permalink
Change addCypherVersion option to addCypherVersionPrefix as a boolean
Browse files Browse the repository at this point in the history
  • Loading branch information
angrykoala committed Jan 28, 2025
1 parent ce773e8 commit 48fda92
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .changeset/soft-socks-count.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Add `version` to `cypherQueryOptions` in context to add a Cypher version with `C
```js
{
cypherQueryOptions: {
version: "5",
addCypherVersionPrefix: true,
},
}
```
Expand Down
10 changes: 7 additions & 3 deletions packages/graphql/src/classes/Executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import {
} from "../constants";
import { debugCypherAndParams } from "../debug/debug-cypher-and-params";
import type { CypherQueryOptions } from "../types";
import { isInArray } from "../utils/is-in-array";
import {
Neo4jGraphQLAuthenticationError,
Neo4jGraphQLConstraintValidationError,
Expand All @@ -49,6 +50,8 @@ import {

const debug = Debug(DEBUG_EXECUTE);

const SUPPORTED_CYPHER_VERSION = "5";

interface DriverLike {
session(config);
}
Expand Down Expand Up @@ -181,15 +184,16 @@ export class Executor {
}

private getCypherVersionStatement(): string {
if (this.cypherQueryOptions?.version) {
return `CYPHER ${this.cypherQueryOptions.version}\n`;
if (this.cypherQueryOptions?.addCypherVersionPrefix) {
return `CYPHER ${SUPPORTED_CYPHER_VERSION}\n`;
}
return "";
}

private getCypherQueryOptionsStatement(): string {
const ignoredCypherQueryOptions: Array<keyof CypherQueryOptions> = ["addCypherVersionPrefix"];
const cypherQueryOptions = Object.entries(this.cypherQueryOptions ?? []).filter(([key, _value]) => {
return key !== "version";
return !isInArray(ignoredCypherQueryOptions, key);
});
if (cypherQueryOptions.length) {
return `CYPHER ${cypherQueryOptions
Expand Down
2 changes: 1 addition & 1 deletion packages/graphql/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ export interface CypherQueryOptions {
operatorEngine?: "default" | "interpreted" | "compiled";
interpretedPipesFallback?: "default" | "disabled" | "whitelisted_plans_only" | "all";
replan?: "default" | "force" | "skip";
version?: "5";
addCypherVersionPrefix?: boolean;
}

/** Input field for graphql-compose */
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", version: "5" } },
contextValue: { cypherQueryOptions: { runtime: "interpreted", addCypherVersionPrefix: true } },
});

expect(result.errors).toBeFalsy();
Expand Down

0 comments on commit 48fda92

Please sign in to comment.