From 48fda924ad620efadfe915c5fdbd7e08ce3ac9e8 Mon Sep 17 00:00:00 2001 From: angrykoala Date: Tue, 28 Jan 2025 10:41:52 +0000 Subject: [PATCH] Change addCypherVersion option to addCypherVersionPrefix as a boolean --- .changeset/soft-socks-count.md | 2 +- packages/graphql/src/classes/Executor.ts | 10 +++++++--- packages/graphql/src/types/index.ts | 2 +- .../config-options/query-options.int.test.ts | 2 +- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/.changeset/soft-socks-count.md b/.changeset/soft-socks-count.md index 4f90025dc6..2e69ca159d 100644 --- a/.changeset/soft-socks-count.md +++ b/.changeset/soft-socks-count.md @@ -7,7 +7,7 @@ Add `version` to `cypherQueryOptions` in context to add a Cypher version with `C ```js { cypherQueryOptions: { - version: "5", + addCypherVersionPrefix: true, }, } ``` diff --git a/packages/graphql/src/classes/Executor.ts b/packages/graphql/src/classes/Executor.ts index 633e7fae11..294e5ed9a1 100644 --- a/packages/graphql/src/classes/Executor.ts +++ b/packages/graphql/src/classes/Executor.ts @@ -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, @@ -49,6 +50,8 @@ import { const debug = Debug(DEBUG_EXECUTE); +const SUPPORTED_CYPHER_VERSION = "5"; + interface DriverLike { session(config); } @@ -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 = ["addCypherVersionPrefix"]; const cypherQueryOptions = Object.entries(this.cypherQueryOptions ?? []).filter(([key, _value]) => { - return key !== "version"; + return !isInArray(ignoredCypherQueryOptions, key); }); if (cypherQueryOptions.length) { return `CYPHER ${cypherQueryOptions diff --git a/packages/graphql/src/types/index.ts b/packages/graphql/src/types/index.ts index e3a36bf77b..8117a4f63a 100644 --- a/packages/graphql/src/types/index.ts +++ b/packages/graphql/src/types/index.ts @@ -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 */ diff --git a/packages/graphql/tests/integration/config-options/query-options.int.test.ts b/packages/graphql/tests/integration/config-options/query-options.int.test.ts index 7f37a78a0d..db510244c9 100644 --- a/packages/graphql/tests/integration/config-options/query-options.int.test.ts +++ b/packages/graphql/tests/integration/config-options/query-options.int.test.ts @@ -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();