From 24f6d79750918c69294f2b93b9547508fd04df01 Mon Sep 17 00:00:00 2001 From: angrykoala Date: Wed, 14 Aug 2024 13:48:49 +0100 Subject: [PATCH] Fix BigInt constrints #5461 --- .changeset/rude-icons-doubt.md | 5 + .../model-adapters/AttributeAdapter.ts | 3 +- .../tests/integration/issues/5461.int.test.ts | 107 ++++++++++++++++++ 3 files changed, 114 insertions(+), 1 deletion(-) create mode 100644 .changeset/rude-icons-doubt.md create mode 100644 packages/graphql/tests/integration/issues/5461.int.test.ts diff --git a/.changeset/rude-icons-doubt.md b/.changeset/rude-icons-doubt.md new file mode 100644 index 0000000000..5e196570bd --- /dev/null +++ b/.changeset/rude-icons-doubt.md @@ -0,0 +1,5 @@ +--- +"@neo4j/graphql": patch +--- + +Fix unique constraints for BigInt diff --git a/packages/graphql/src/schema-model/attribute/model-adapters/AttributeAdapter.ts b/packages/graphql/src/schema-model/attribute/model-adapters/AttributeAdapter.ts index 55aeff3485..341786940f 100644 --- a/packages/graphql/src/schema-model/attribute/model-adapters/AttributeAdapter.ts +++ b/packages/graphql/src/schema-model/attribute/model-adapters/AttributeAdapter.ts @@ -108,7 +108,8 @@ export class AttributeAdapter { this.typeHelper.isUserScalar() || this.typeHelper.isEnum() || this.typeHelper.isTemporal() || - this.typeHelper.isSpatial() + this.typeHelper.isSpatial() || + this.typeHelper.isBigInt() ); } diff --git a/packages/graphql/tests/integration/issues/5461.int.test.ts b/packages/graphql/tests/integration/issues/5461.int.test.ts new file mode 100644 index 0000000000..e5fc22ba37 --- /dev/null +++ b/packages/graphql/tests/integration/issues/5461.int.test.ts @@ -0,0 +1,107 @@ +/* + * Copyright (c) "Neo4j" + * Neo4j Sweden AB [http://neo4j.com] + * + * This file is part of Neo4j. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import type { Driver } from "neo4j-driver"; +import { generate } from "randomstring"; +import { isMultiDbUnsupportedError } from "../../utils/is-multi-db-unsupported-error"; +import { TestHelper } from "../../utils/tests-helper"; + +describe("https://github.com/neo4j/graphql/issues/5461", () => { + const testHelper = new TestHelper(); + let driver: Driver; + let databaseName: string; + let MULTIDB_SUPPORT = true; + + beforeAll(async () => { + databaseName = generate({ readable: true, charset: "alphabetic" }); + + try { + await testHelper.createDatabase(databaseName); + } catch (e) { + if (e instanceof Error) { + if (isMultiDbUnsupportedError(e)) { + // No multi-db support, so we skip tests + MULTIDB_SUPPORT = false; + await testHelper.close(); + } else { + throw e; + } + } + } + }); + + beforeEach(async () => { + if (MULTIDB_SUPPORT) { + driver = await testHelper.getDriver(); + } + }); + + afterEach(async () => { + if (MULTIDB_SUPPORT) { + await testHelper.close(); + } + }); + + afterAll(async () => { + if (MULTIDB_SUPPORT) { + await testHelper.dropDatabase(); + await testHelper.close(); + } + }); + + test("should create a constraint if it doesn't exist and specified in options", async () => { + // Skip if multi-db not supported + if (!MULTIDB_SUPPORT) { + console.log("MULTIDB_SUPPORT NOT AVAILABLE - SKIPPING"); + return; + } + + const type = testHelper.createUniqueType("Book"); + + const typeDefs = ` + type ${type.name} { + isbn: BigInt! @unique + age: BigInt! + } + `; + + const neoSchema = await testHelper.initNeo4jGraphQL({ typeDefs }); + await neoSchema.getSchema(); + + await expect( + neoSchema.assertIndexesAndConstraints({ + driver, + sessionConfig: { database: databaseName }, + options: { create: true }, + }) + ).resolves.not.toThrow(); + + const cypher = "SHOW UNIQUE CONSTRAINTS"; + + const result = await testHelper.executeCypher(cypher); + + expect( + result.records + .map((record) => { + return record.toObject(); + }) + .filter((record) => record.labelsOrTypes.includes(type.name)) + ).toHaveLength(1); + }); +});