diff --git a/.changeset/poor-fans-smile.md b/.changeset/poor-fans-smile.md new file mode 100644 index 0000000000..8c7110d90c --- /dev/null +++ b/.changeset/poor-fans-smile.md @@ -0,0 +1,5 @@ +--- +"@neo4j/graphql": major +--- + +`neo4jDatabaseInfo` has been removed from the context. It is our belief that this has little utility in the library. If you regularly use different drivers connected to _different versions_ of Neo4j and require this feature, please raise an issue: https://github.com/neo4j/graphql/issues/new/choose diff --git a/docs/modules/ROOT/pages/reference/driver-configuration.adoc b/docs/modules/ROOT/pages/reference/driver-configuration.adoc index 737d705004..114ec44fd6 100644 --- a/docs/modules/ROOT/pages/reference/driver-configuration.adoc +++ b/docs/modules/ROOT/pages/reference/driver-configuration.adoc @@ -218,43 +218,6 @@ await startStandaloneServer(server, { }); ---- -== Specifying Neo4j version - -When a connection is established, the library automatically detect the version of the Neo4j instance connected. -The version will be then stored and used for the following queries. -It is also possible to specify manually the Neo4j version in the Context. - -=== Context - -[source, javascript, indent=0] ----- -import { ApolloServer } from '@apollo/server'; -import { startStandaloneServer } from '@apollo/server/standalone'; -import { Neo4jDatabaseInfo, Neo4jGraphQL } from "@neo4j/graphql"; -import neo4j from "neo4j-driver"; - -const typeDefs = `#graphql - type User { - name: String - } -`; - -const driver = neo4j.driver( - "bolt://localhost:7687", - neo4j.auth.basic("neo4j", "password") -); - -const neoSchema = new Neo4jGraphQL({ typeDefs, driver }); - -const server = new ApolloServer({ - schema: await neoSchema.getSchema(), -}); - -await startStandaloneServer(server, { - context: async ({ req }) => ({ req, neo4jDatabaseInfo: new Neo4jDatabaseInfo("4.4") }), -}); ----- - [[driver-configuration-bookmarks]] == Specifying Neo4j Bookmarks diff --git a/packages/graphql/src/index.ts b/packages/graphql/src/index.ts index 29a74a3e1b..4a18aefb15 100644 --- a/packages/graphql/src/index.ts +++ b/packages/graphql/src/index.ts @@ -21,7 +21,6 @@ import { CartesianPoint } from "./graphql/objects/CartesianPoint"; import { Point } from "./graphql/objects/Point"; export { - Neo4jDatabaseInfo, Neo4jGraphQL, Neo4jGraphQLAuthenticationError, Neo4jGraphQLConstructor, diff --git a/packages/graphql/src/translate/create-aggregate-where-and-params.ts b/packages/graphql/src/translate/create-aggregate-where-and-params.ts index a21a3bf141..3ba86236fc 100644 --- a/packages/graphql/src/translate/create-aggregate-where-and-params.ts +++ b/packages/graphql/src/translate/create-aggregate-where-and-params.ts @@ -18,7 +18,7 @@ */ import Cypher from "@neo4j/cypher-builder"; -import type { Neo4jDatabaseInfo, Node, Relationship } from "../classes"; +import type { Node, Relationship } from "../classes"; import type { RelationField, Context, GraphQLWhereArg, PredicateReturn } from "../types"; import type { AggregationFieldRegexGroups } from "./where/utils"; import { aggregationFieldRegEx, whereRegEx } from "./where/utils"; @@ -256,8 +256,6 @@ function createEntityOperation( param: paramName, durationField, pointField, - // Casting because this is definitely assigned in the wrapper - neo4jDatabaseInfo: context.neo4jDatabaseInfo as Neo4jDatabaseInfo, }); const dbFieldName = mapToDbProperty(refNodeOrRelation, fieldName); const collectedProperty = diff --git a/packages/graphql/src/translate/where/property-operations/create-comparison-operation.ts b/packages/graphql/src/translate/where/property-operations/create-comparison-operation.ts index 1558cedce1..368063854e 100644 --- a/packages/graphql/src/translate/where/property-operations/create-comparison-operation.ts +++ b/packages/graphql/src/translate/where/property-operations/create-comparison-operation.ts @@ -17,7 +17,6 @@ * limitations under the License. */ -import type { Neo4jDatabaseInfo } from "../../../classes/Neo4jDatabaseInfo"; import type { PointField, PrimitiveField } from "../../../types"; import Cypher from "@neo4j/cypher-builder"; import { createPointComparisonOperation } from "./create-point-comparison-operation"; @@ -29,14 +28,12 @@ export function createComparisonOperation({ param, durationField, pointField, - neo4jDatabaseInfo, }: { operator: string | undefined; propertyRefOrCoalesce: Cypher.Property | Cypher.Function | Cypher.Variable; param: Cypher.Param | Cypher.Property | Cypher.Function; durationField: PrimitiveField | undefined; pointField: PointField | undefined; - neo4jDatabaseInfo: Neo4jDatabaseInfo; }): Cypher.ComparisonOp { // TODO: consider if this conditional is the correct solution - should we make the function compatible? if (!(param instanceof Cypher.Function) && pointField) { @@ -45,7 +42,6 @@ export function createComparisonOperation({ propertyRefOrCoalesce, param, pointField, - neo4jDatabaseInfo, }); } diff --git a/packages/graphql/src/translate/where/property-operations/create-point-comparison-operation.ts b/packages/graphql/src/translate/where/property-operations/create-point-comparison-operation.ts index 1bdac49830..b32b8fd5ee 100644 --- a/packages/graphql/src/translate/where/property-operations/create-point-comparison-operation.ts +++ b/packages/graphql/src/translate/where/property-operations/create-point-comparison-operation.ts @@ -17,7 +17,6 @@ * limitations under the License. */ -import type { Neo4jDatabaseInfo } from "../../../classes/Neo4jDatabaseInfo"; import type { PointField } from "../../../types"; import Cypher from "@neo4j/cypher-builder"; @@ -27,15 +26,13 @@ export function createPointComparisonOperation({ propertyRefOrCoalesce, param, pointField, - neo4jDatabaseInfo, }: { operator: string | undefined; propertyRefOrCoalesce: Cypher.Property | Cypher.Function | Cypher.Variable; param: Cypher.Param | Cypher.Property; pointField: PointField; - neo4jDatabaseInfo: Neo4jDatabaseInfo; }): Cypher.ComparisonOp { - const pointDistance = createPointDistanceExpression(propertyRefOrCoalesce, param, neo4jDatabaseInfo); + const pointDistance = createPointDistanceExpression(propertyRefOrCoalesce, param); const distanceRef = param.property("distance"); switch (operator || "EQ") { @@ -77,14 +74,7 @@ function createPointListComprehension(param: Cypher.Param | Cypher.Property): Cy return new Cypher.ListComprehension(comprehensionVar, param).map(mapPoint); } -function createPointDistanceExpression( - property: Cypher.Expr, - param: Cypher.Param | Cypher.Property, - neo4jDatabaseInfo: Neo4jDatabaseInfo -): Cypher.Function { +function createPointDistanceExpression(property: Cypher.Expr, param: Cypher.Param | Cypher.Property): Cypher.Function { const nestedPointRef = param.property("point"); - if (neo4jDatabaseInfo.gte("4.4")) { - return Cypher.pointDistance(property, Cypher.point(nestedPointRef)); - } - return Cypher.distance(property, Cypher.point(nestedPointRef)); + return Cypher.pointDistance(property, Cypher.point(nestedPointRef)); } diff --git a/packages/graphql/src/translate/where/property-operations/create-property-where.ts b/packages/graphql/src/translate/where/property-operations/create-property-where.ts index c279c464d6..13fc084acd 100644 --- a/packages/graphql/src/translate/where/property-operations/create-property-where.ts +++ b/packages/graphql/src/translate/where/property-operations/create-property-where.ts @@ -19,7 +19,7 @@ import type { Context, PredicateReturn } from "../../../types"; import Cypher from "@neo4j/cypher-builder"; -import type { GraphElement, Neo4jDatabaseInfo } from "../../../classes"; +import type { GraphElement } from "../../../classes"; import { Node } from "../../../classes"; import type { WhereRegexGroups } from "../utils"; import { whereRegEx } from "../utils"; @@ -168,8 +168,6 @@ export function createPropertyWhere({ operator, durationField, pointField, - // Casting because this is definitely assigned in the wrapper - neo4jDatabaseInfo: context.neo4jDatabaseInfo as Neo4jDatabaseInfo, }); if (isNot) { return { diff --git a/packages/graphql/src/types/index.ts b/packages/graphql/src/types/index.ts index 31ccebbfe2..76157acec8 100644 --- a/packages/graphql/src/types/index.ts +++ b/packages/graphql/src/types/index.ts @@ -24,7 +24,7 @@ import type { Directive } from "graphql-compose"; import type { ResolveTree } from "graphql-parse-resolve-info"; import type { JWTVerifyOptions, RemoteJWKSetOptions } from "jose"; import type { Integer } from "neo4j-driver"; -import type { Node, Relationship } from "../classes"; +import type { Neo4jDatabaseInfo, Node, Relationship } from "../classes"; import type { Executor } from "../classes/Executor"; import type { RelationshipNestedOperationsOption, RelationshipQueryDirectionOption } from "../constants"; import type { Neo4jGraphQLSchemaModel } from "../schema-model/Neo4jGraphQLSchemaModel"; @@ -61,6 +61,7 @@ export interface Context extends Neo4jGraphQLContext { executor: Executor; extensions?: Record; authorization: AuthorizationContext; + neo4jDatabaseInfo?: Neo4jDatabaseInfo; [k: string]: any; } diff --git a/packages/graphql/src/types/neo4j-graphql-context.ts b/packages/graphql/src/types/neo4j-graphql-context.ts index 9de936e293..b83cdfde32 100644 --- a/packages/graphql/src/types/neo4j-graphql-context.ts +++ b/packages/graphql/src/types/neo4j-graphql-context.ts @@ -19,7 +19,6 @@ import type { Driver, Session, Transaction } from "neo4j-driver"; import type { CypherQueryOptions, DriverConfig, RequestLike } from "."; -import type { Neo4jDatabaseInfo } from "../classes"; import type { JWTPayload } from "jose"; export interface Neo4jGraphQLContext { @@ -49,10 +48,6 @@ export interface Neo4jGraphQLContext { * ``` */ jwt?: JWTPayload; - /** - * @deprecated This property will be removed in 4.0.0. - */ - neo4jDatabaseInfo?: Neo4jDatabaseInfo; /** * Configures which {@link https://neo4j.com/docs/cypher-manual/current/query-tuning/query-options/ | Cypher query options} * when executing the translated query. diff --git a/packages/graphql/tests/e2e/neo4jgraphql/neo4j-database-info.test.ts b/packages/graphql/tests/e2e/neo4jgraphql/neo4j-database-info.test.ts index 3e1b564bec..a362012caa 100644 --- a/packages/graphql/tests/e2e/neo4jgraphql/neo4j-database-info.test.ts +++ b/packages/graphql/tests/e2e/neo4jgraphql/neo4j-database-info.test.ts @@ -20,11 +20,12 @@ import type { Driver } from "neo4j-driver"; import type { Response } from "supertest"; import supertest from "supertest"; -import { Neo4jDatabaseInfo, Neo4jGraphQL } from "../../../src/"; +import { Neo4jGraphQL } from "../../../src/"; import { UniqueType } from "../../utils/graphql-types"; import type { TestGraphQLServer } from "../setup/apollo-server"; import { ApolloTestServer } from "../setup/apollo-server"; import Neo4j from "../setup/neo4j"; +import { Neo4jDatabaseInfo } from "../../../src/classes"; describe("Create with specific neo4jDatabaseInfo set correctly", () => { let neo4j: Neo4j; diff --git a/packages/graphql/tests/performance/translation/utils/translate-query.ts b/packages/graphql/tests/performance/translation/utils/translate-query.ts index 551ba8dfe4..9294013901 100644 --- a/packages/graphql/tests/performance/translation/utils/translate-query.ts +++ b/packages/graphql/tests/performance/translation/utils/translate-query.ts @@ -37,7 +37,7 @@ export async function translateQuery( } ): Promise<{ cypher: string; params: Record }> { const driverBuilder = new DriverBuilder(); - const neo4jDatabaseInfo = new Neo4jDatabaseInfo(options?.neo4jVersion ?? "4.3"); + const neo4jDatabaseInfo = new Neo4jDatabaseInfo(options?.neo4jVersion ?? "4.4"); let contextValue: Record = { driver: driverBuilder.instance(), neo4jDatabaseInfo }; if (options?.req) { contextValue.req = options.req; diff --git a/packages/graphql/tests/tck/types/point.test.ts b/packages/graphql/tests/tck/types/point.test.ts index 3cd74e1795..f463409a79 100644 --- a/packages/graphql/tests/tck/types/point.test.ts +++ b/packages/graphql/tests/tck/types/point.test.ts @@ -179,21 +179,6 @@ describe("Cypher Points", () => { }); describe("tests using describe or point.describe", () => { - let verifyTCK; - - beforeAll(() => { - if (process.env.VERIFY_TCK) { - verifyTCK = process.env.VERIFY_TCK; - delete process.env.VERIFY_TCK; - } - }); - - afterAll(() => { - if (verifyTCK) { - process.env.VERIFY_TCK = verifyTCK; - } - }); - test("Simple Point LT query", async () => { const query = gql` { @@ -375,198 +360,6 @@ describe("Cypher Points", () => { }" `); }); - - test("Simple Point LT query (4.4)", async () => { - const query = gql` - { - pointContainers(where: { point_LT: { point: { longitude: 1.1, latitude: 2.2 }, distance: 3.3 } }) { - point { - longitude - latitude - } - } - } - `; - - const result = await translateQuery(neoSchema, query, { - neo4jVersion: "4.4", - }); - - expect(formatCypher(result.cypher)).toMatchInlineSnapshot(` - "MATCH (this:\`PointContainer\`) - WHERE point.distance(this.point, point($param0.point)) < $param0.distance - RETURN this { point: CASE - WHEN this.point IS NOT NULL THEN { point: this.point } - ELSE NULL - END } AS this" - `); - - expect(formatParams(result.params)).toMatchInlineSnapshot(` - "{ - \\"param0\\": { - \\"point\\": { - \\"longitude\\": 1.1, - \\"latitude\\": 2.2 - }, - \\"distance\\": 3.3 - } - }" - `); - }); - - test("Simple Point LTE query (4.4)", async () => { - const query = gql` - { - pointContainers(where: { point_LTE: { point: { longitude: 1.1, latitude: 2.2 }, distance: 3.3 } }) { - point { - longitude - latitude - } - } - } - `; - - const result = await translateQuery(neoSchema, query, { - neo4jVersion: "4.4", - }); - - expect(formatCypher(result.cypher)).toMatchInlineSnapshot(` - "MATCH (this:\`PointContainer\`) - WHERE point.distance(this.point, point($param0.point)) <= $param0.distance - RETURN this { point: CASE - WHEN this.point IS NOT NULL THEN { point: this.point } - ELSE NULL - END } AS this" - `); - - expect(formatParams(result.params)).toMatchInlineSnapshot(` - "{ - \\"param0\\": { - \\"point\\": { - \\"longitude\\": 1.1, - \\"latitude\\": 2.2 - }, - \\"distance\\": 3.3 - } - }" - `); - }); - - test("Simple Point GT query (4.4)", async () => { - const query = gql` - { - pointContainers(where: { point_GT: { point: { longitude: 1.1, latitude: 2.2 }, distance: 3.3 } }) { - point { - longitude - latitude - } - } - } - `; - - const result = await translateQuery(neoSchema, query, { - neo4jVersion: "4.4", - }); - - expect(formatCypher(result.cypher)).toMatchInlineSnapshot(` - "MATCH (this:\`PointContainer\`) - WHERE point.distance(this.point, point($param0.point)) > $param0.distance - RETURN this { point: CASE - WHEN this.point IS NOT NULL THEN { point: this.point } - ELSE NULL - END } AS this" - `); - - expect(formatParams(result.params)).toMatchInlineSnapshot(` - "{ - \\"param0\\": { - \\"point\\": { - \\"longitude\\": 1.1, - \\"latitude\\": 2.2 - }, - \\"distance\\": 3.3 - } - }" - `); - }); - - test("Simple Point GTE query (4.4)", async () => { - const query = gql` - { - pointContainers(where: { point_GTE: { point: { longitude: 1.1, latitude: 2.2 }, distance: 3.3 } }) { - point { - longitude - latitude - } - } - } - `; - - const result = await translateQuery(neoSchema, query, { - neo4jVersion: "4.4", - }); - - expect(formatCypher(result.cypher)).toMatchInlineSnapshot(` - "MATCH (this:\`PointContainer\`) - WHERE point.distance(this.point, point($param0.point)) >= $param0.distance - RETURN this { point: CASE - WHEN this.point IS NOT NULL THEN { point: this.point } - ELSE NULL - END } AS this" - `); - - expect(formatParams(result.params)).toMatchInlineSnapshot(` - "{ - \\"param0\\": { - \\"point\\": { - \\"longitude\\": 1.1, - \\"latitude\\": 2.2 - }, - \\"distance\\": 3.3 - } - }" - `); - }); - - test("Simple Point DISTANCE query (4.4)", async () => { - const query = gql` - { - pointContainers( - where: { point_DISTANCE: { point: { longitude: 1.1, latitude: 2.2 }, distance: 3.3 } } - ) { - point { - longitude - latitude - } - } - } - `; - - const result = await translateQuery(neoSchema, query, { - neo4jVersion: "4.4", - }); - - expect(formatCypher(result.cypher)).toMatchInlineSnapshot(` - "MATCH (this:\`PointContainer\`) - WHERE point.distance(this.point, point($param0.point)) = $param0.distance - RETURN this { point: CASE - WHEN this.point IS NOT NULL THEN { point: this.point } - ELSE NULL - END } AS this" - `); - - expect(formatParams(result.params)).toMatchInlineSnapshot(` - "{ - \\"param0\\": { - \\"point\\": { - \\"longitude\\": 1.1, - \\"latitude\\": 2.2 - }, - \\"distance\\": 3.3 - } - }" - `); - }); }); test("Simple Point create mutation", async () => {