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

Fix BigInt constraints #5461 #5468

Merged
merged 1 commit into from
Aug 14, 2024
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
5 changes: 5 additions & 0 deletions .changeset/rude-icons-doubt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@neo4j/graphql": patch
---

Fix unique constraints for BigInt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
);
}

Expand Down
107 changes: 107 additions & 0 deletions packages/graphql/tests/integration/issues/5461.int.test.ts
Original file line number Diff line number Diff line change
@@ -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);
});
});
Loading