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

Bugfix/dbms version check #550

Merged
merged 3 commits into from
Oct 28, 2021
Merged
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
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
14.16.0
lts/*
2 changes: 1 addition & 1 deletion packages/graphql/src/classes/Neo4jGraphQL.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import type { DriverConfig, CypherQueryOptions } from "../types";
import { makeAugmentedSchema } from "../schema";
import Node from "./Node";
import Relationship from "./Relationship";
import { checkNeo4jCompat } from "../utils";
import checkNeo4jCompat from "./utils/verify-database";
danstarns marked this conversation as resolved.
Show resolved Hide resolved
import { getJWT } from "../auth/index";
import { DEBUG_GRAPHQL } from "../constants";
import getNeo4jResolveTree from "../utils/get-neo4j-resolve-tree";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@

import { Driver, Session } from "neo4j-driver";
import checkNeo4jCompat from "./verify-database";
import { MIN_NEO4J_VERSION, MIN_APOC_VERSION, REQUIRED_APOC_FUNCTIONS, REQUIRED_APOC_PROCEDURES } from "../constants";
import { DriverConfig } from "../types";
import { REQUIRED_APOC_FUNCTIONS, REQUIRED_APOC_PROCEDURES, MIN_VERSIONS } from "../../constants";
import { DriverConfig } from "../../types";

describe("checkNeo4jCompat", () => {
test("should add driver config to session", async () => {
const minVersion = MIN_VERSIONS[0];

// @ts-ignore
const fakeSession: Session = {
// @ts-ignore
Expand All @@ -32,8 +34,8 @@ describe("checkNeo4jCompat", () => {
records: [
{
toObject: () => ({
version: MIN_NEO4J_VERSION,
apocVersion: MIN_APOC_VERSION,
version: minVersion.neo4j,
apocVersion: `${minVersion.majorMinor}.0.10`,
functions: REQUIRED_APOC_FUNCTIONS,
procedures: REQUIRED_APOC_PROCEDURES,
}),
Expand Down Expand Up @@ -74,7 +76,7 @@ describe("checkNeo4jCompat", () => {
{
toObject: () => ({
version: invalidVersion,
apocVersion: MIN_APOC_VERSION,
apocVersion: "2.3.0.0",
functions: REQUIRED_APOC_FUNCTIONS,
procedures: REQUIRED_APOC_PROCEDURES,
}),
Expand All @@ -94,7 +96,7 @@ describe("checkNeo4jCompat", () => {
};

await expect(checkNeo4jCompat({ driver: fakeDriver })).rejects.toThrow(
`Encountered the following DBMS compatiblility issues:\nExpected minimum Neo4j version: '${MIN_NEO4J_VERSION}' received: '${invalidVersion}'`
`Encountered the following DBMS compatiblility issues:\nExpected Neo4j version '${MIN_VERSIONS[0].majorMinor}' or greater, received: '${invalidVersion}'`
);
});

Expand All @@ -107,7 +109,7 @@ describe("checkNeo4jCompat", () => {
{
toObject: () => ({
version: "4.1.10",
apocVersion: MIN_APOC_VERSION,
apocVersion: "4.1.0.0",
functions: REQUIRED_APOC_FUNCTIONS,
procedures: REQUIRED_APOC_PROCEDURES,
}),
Expand Down Expand Up @@ -137,8 +139,8 @@ describe("checkNeo4jCompat", () => {
records: [
{
toObject: () => ({
version: "4.2-aura",
apocVersion: MIN_APOC_VERSION,
version: "4.0-aura",
apocVersion: "We trust Aura APOC version",
functions: REQUIRED_APOC_FUNCTIONS,
procedures: REQUIRED_APOC_PROCEDURES,
}),
Expand Down Expand Up @@ -170,7 +172,7 @@ describe("checkNeo4jCompat", () => {
records: [
{
toObject: () => ({
version: MIN_NEO4J_VERSION,
version: MIN_VERSIONS[0].neo4j,
apocVersion: invalidApocVersion,
functions: REQUIRED_APOC_FUNCTIONS,
procedures: REQUIRED_APOC_PROCEDURES,
Expand All @@ -191,20 +193,22 @@ describe("checkNeo4jCompat", () => {
};

await expect(checkNeo4jCompat({ driver: fakeDriver })).rejects.toThrow(
`Encountered the following DBMS compatiblility issues:\nExpected minimum APOC version: '${MIN_APOC_VERSION}' received: '${invalidApocVersion}'`
`Encountered the following DBMS compatiblility issues:\nAPOC version does not match Neo4j version '4.1', received: '${invalidApocVersion}'`
);
});

test("should throw missing APOC functions", async () => {
const minVersion = MIN_VERSIONS[0];

// @ts-ignore
const fakeSession: Session = {
// @ts-ignore
run: () => ({
records: [
{
toObject: () => ({
version: MIN_NEO4J_VERSION,
apocVersion: MIN_APOC_VERSION,
version: minVersion.neo4j,
apocVersion: `${minVersion.majorMinor}.0.10`,
functions: [],
procedures: REQUIRED_APOC_PROCEDURES,
}),
Expand All @@ -231,15 +235,17 @@ describe("checkNeo4jCompat", () => {
});

test("should throw missing APOC procedures", async () => {
const minVersion = MIN_VERSIONS[0];

// @ts-ignore
const fakeSession: Session = {
// @ts-ignore
run: () => ({
records: [
{
toObject: () => ({
version: MIN_NEO4J_VERSION,
apocVersion: MIN_APOC_VERSION,
version: minVersion.neo4j,
apocVersion: `${minVersion.majorMinor}.0.10`,
functions: REQUIRED_APOC_FUNCTIONS,
procedures: [],
}),
Expand All @@ -266,15 +272,17 @@ describe("checkNeo4jCompat", () => {
});

test("should throw no errors with valid DB", async () => {
const minVersion = MIN_VERSIONS[0];

// @ts-ignore
const fakeSession: Session = {
// @ts-ignore
run: () => ({
records: [
{
toObject: () => ({
version: MIN_NEO4J_VERSION,
apocVersion: MIN_APOC_VERSION,
version: minVersion.neo4j,
apocVersion: `${minVersion.majorMinor}.0.10`,
functions: REQUIRED_APOC_FUNCTIONS,
procedures: REQUIRED_APOC_PROCEDURES,
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@

import { Driver } from "neo4j-driver";
import semver from "semver";
import { MIN_NEO4J_VERSION, MIN_APOC_VERSION, REQUIRED_APOC_FUNCTIONS, REQUIRED_APOC_PROCEDURES } from "../constants";
import { DriverConfig } from "../types";
import { REQUIRED_APOC_FUNCTIONS, REQUIRED_APOC_PROCEDURES, MIN_VERSIONS } from "../../constants";
import { DriverConfig } from "../../types";

interface DBInfo {
version: string;
Expand Down Expand Up @@ -69,12 +69,30 @@ async function checkNeo4jCompat({ driver, driverConfig }: { driver: Driver; driv
const info = result.records[0].toObject() as DBInfo;
const errors: string[] = [];

if (semver.lt(semver.coerce(info.version), MIN_NEO4J_VERSION)) {
errors.push(`Expected minimum Neo4j version: '${MIN_NEO4J_VERSION}' received: '${info.version}'`);
}
if (!info.version.includes("aura")) {
const minimumVersions = MIN_VERSIONS.find(({ majorMinor }) => info.version.startsWith(majorMinor));
const coercedNeo4jVersion = semver.coerce(info.version);

if (!minimumVersions) {
// If new major/minor version comes out, this will stop error being thrown
if (semver.lt(coercedNeo4jVersion, MIN_VERSIONS[0].neo4j)) {
errors.push(
`Expected Neo4j version '${MIN_VERSIONS[0].majorMinor}' or greater, received: '${info.version}'`
);
}
} else {
if (semver.lt(coercedNeo4jVersion, minimumVersions.neo4j)) {
errors.push(
`Expected minimum Neo4j version: '${minimumVersions.neo4j}' received: '${info.version}'`
);
}

if (semver.lt(semver.coerce(info.apocVersion), MIN_APOC_VERSION)) {
errors.push(`Expected minimum APOC version: '${MIN_APOC_VERSION}' received: '${info.apocVersion}'`);
if (!info.apocVersion.startsWith(minimumVersions.majorMinor)) {
errors.push(
`APOC version does not match Neo4j version '${minimumVersions.majorMinor}', received: '${info.apocVersion}'`
);
}
}
}

const missingFunctions = REQUIRED_APOC_FUNCTIONS.filter((f) => !info.functions.includes(f));
Expand Down
7 changes: 5 additions & 2 deletions packages/graphql/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@ const DEBUG_PREFIX = "@neo4j/graphql";

export const AUTH_FORBIDDEN_ERROR = "@neo4j/graphql/FORBIDDEN";
export const AUTH_UNAUTHENTICATED_ERROR = "@neo4j/graphql/UNAUTHENTICATED";
export const MIN_NEO4J_VERSION = "4.1.5";
export const MIN_APOC_VERSION = "4.1.0";
export const MIN_VERSIONS = [
{ majorMinor: "4.1", neo4j: "4.1.5" },
{ majorMinor: "4.2", neo4j: "4.2.9" },
{ majorMinor: "4.3", neo4j: "4.3.2" },
];
export const REQUIRED_APOC_FUNCTIONS = [
"apoc.util.validatePredicate",
"apoc.cypher.runFirstColumn",
Expand Down
1 change: 0 additions & 1 deletion packages/graphql/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,3 @@

export { default as trimmer } from "./trimmer";
export { default as execute } from "./execute";
export { default as checkNeo4jCompat } from "./verify-database";
danstarns marked this conversation as resolved.
Show resolved Hide resolved