diff --git a/.changeset/afraid-cows-beg.md b/.changeset/afraid-cows-beg.md new file mode 100644 index 0000000000..98606fbb36 --- /dev/null +++ b/.changeset/afraid-cows-beg.md @@ -0,0 +1,5 @@ +--- +"@neo4j/graphql": patch +--- + +The `options` argument of `assertIndexesAndConstraints` has been deprecated and the creation of indexes and constraints will no longer be support in the next major version of the library. diff --git a/packages/graphql/src/classes/Neo4jGraphQL.ts b/packages/graphql/src/classes/Neo4jGraphQL.ts index c08c0f0f93..d165e5ceaa 100644 --- a/packages/graphql/src/classes/Neo4jGraphQL.ts +++ b/packages/graphql/src/classes/Neo4jGraphQL.ts @@ -166,6 +166,9 @@ class Neo4jGraphQL { }: { driver?: Driver; sessionConfig?: Neo4jGraphQLSessionConfig; + /** + * @deprecated The ability to create indexes and constraints will be removed in version 6.0.0 + */ options?: AssertIndexesAndConstraintsOptions; } = {}): Promise { if (!(this.executableSchema || this.subgraphSchema)) { diff --git a/packages/graphql/tests/integration/directives/cypher/filtering/cypher-filtering-list-auth.int.test.ts b/packages/graphql/tests/integration/directives/cypher/filtering/cypher-filtering-list-auth.int.test.ts index 83e82037d8..94138cacdb 100644 --- a/packages/graphql/tests/integration/directives/cypher/filtering/cypher-filtering-list-auth.int.test.ts +++ b/packages/graphql/tests/integration/directives/cypher/filtering/cypher-filtering-list-auth.int.test.ts @@ -161,14 +161,14 @@ describe("cypher directive filtering - List Auth", () => { expect(gqlResult.errors).toBeFalsy(); expect(gqlResult?.data).toEqual({ - [Movie.plural]: [ + [Movie.plural]: expect.toIncludeSameMembers([ { custom_field: ["a", "b", "c"], }, { custom_field: ["bbb", "a", "bbb"], }, - ], + ]), }); }); diff --git a/packages/graphql/tests/integration/directives/fulltext/fulltext-query.int.test.ts b/packages/graphql/tests/integration/directives/fulltext/fulltext-query.int.test.ts index eadc41dc65..db01788009 100644 --- a/packages/graphql/tests/integration/directives/fulltext/fulltext-query.int.test.ts +++ b/packages/graphql/tests/integration/directives/fulltext/fulltext-query.int.test.ts @@ -134,11 +134,13 @@ describe("@fulltext directive", () => { neoSchema = await testHelper.initNeo4jGraphQL({ typeDefs, }); + + await testHelper.createFulltextIndex(`${personType.name}Index`, personType.name, ["name"]); + await neoSchema.getSchema(); await neoSchema.assertIndexesAndConstraints({ driver, sessionConfig: { database: databaseName }, - options: { create: true }, }); await testHelper.executeCypher( @@ -1244,11 +1246,13 @@ describe("@fulltext directive", () => { }, }, }); + + await testHelper.createFulltextIndex(`${personType.name}Index`, personType.name, ["name"]); + await neoSchema.getSchema(); await neoSchema.assertIndexesAndConstraints({ driver, sessionConfig: { database: databaseName }, - options: { create: true }, }); const query = ` @@ -1305,11 +1309,13 @@ describe("@fulltext directive", () => { }, }, }); + + await testHelper.createFulltextIndex(`${personType.name}Index`, personType.name, ["name"]); + await neoSchema.getSchema(); await neoSchema.assertIndexesAndConstraints({ driver, sessionConfig: { database: databaseName }, - options: { create: true }, }); const query = ` @@ -1366,11 +1372,13 @@ describe("@fulltext directive", () => { }, }, }); + + await testHelper.createFulltextIndex(`${personType.name}Index`, personType.name, ["name"]); + await neoSchema.getSchema(); await neoSchema.assertIndexesAndConstraints({ driver, sessionConfig: { database: databaseName }, - options: { create: true }, }); const query = ` @@ -1442,11 +1450,13 @@ describe("@fulltext directive", () => { }, }, }); + + await testHelper.createFulltextIndex(`${personType.name}Index`, personType.name, ["name"]); + await neoSchema.getSchema(); await neoSchema.assertIndexesAndConstraints({ driver, sessionConfig: { database: databaseName }, - options: { create: true }, }); const query = ` @@ -1498,11 +1508,13 @@ describe("@fulltext directive", () => { }, }, }); + + await testHelper.createFulltextIndex(`${personType.name}Index`, personType.name, ["name"]); + await neoSchema.getSchema(); await neoSchema.assertIndexesAndConstraints({ driver, sessionConfig: { database: databaseName }, - options: { create: true }, }); const query = ` @@ -1557,11 +1569,13 @@ describe("@fulltext directive", () => { }, }, }); + + await testHelper.createFulltextIndex(`${personType.name}Index`, personType.name, ["name"]); + await neoSchema.getSchema(); await neoSchema.assertIndexesAndConstraints({ driver, sessionConfig: { database: databaseName }, - options: { create: true }, }); const query = ` @@ -1617,11 +1631,13 @@ describe("@fulltext directive", () => { }, }, }); + + await testHelper.createFulltextIndex(`${personType.name}Index`, personType.name, ["name"]); + await neoSchema.getSchema(); await neoSchema.assertIndexesAndConstraints({ driver, sessionConfig: { database: databaseName }, - options: { create: true }, }); const query = ` @@ -1669,11 +1685,13 @@ describe("@fulltext directive", () => { neoSchema = await testHelper.initNeo4jGraphQL({ typeDefs, }); + + await testHelper.createFulltextIndex(`${movieType.name}Index`, movieType.name, ["title", "description"]); + await neoSchema.getSchema(); await neoSchema.assertIndexesAndConstraints({ driver, sessionConfig: { database: databaseName }, - options: { create: true }, }); const query = ` @@ -1736,11 +1754,13 @@ describe("@fulltext directive", () => { neoSchema = await testHelper.initNeo4jGraphQL({ typeDefs, }); + + await testHelper.createFulltextIndex(`${personType.name}CustomIndex`, personType.name, ["name"]); + await neoSchema.getSchema(); await neoSchema.assertIndexesAndConstraints({ driver, sessionConfig: { database: databaseName }, - options: { create: true }, }); const query = ` @@ -1793,11 +1813,13 @@ describe("@fulltext directive", () => { neoSchema = await testHelper.initNeo4jGraphQL({ typeDefs, }); + + await testHelper.createFulltextIndex(`${movieType.name}Index`, movieType.name, ["title", "description"]); + await neoSchema.getSchema(); await neoSchema.assertIndexesAndConstraints({ driver, sessionConfig: { database: databaseName }, - options: { create: true }, }); const query = ` @@ -1862,11 +1884,14 @@ describe("@fulltext directive", () => { neoSchema = await testHelper.initNeo4jGraphQL({ typeDefs, }); + + await testHelper.createFulltextIndex(`${movieType.name}CustomIndex`, movieType.name, ["title"]); + await testHelper.createFulltextIndex(`${movieType.name}CustomIndex2`, movieType.name, ["description"]); + await neoSchema.getSchema(); await neoSchema.assertIndexesAndConstraints({ driver, sessionConfig: { database: databaseName }, - options: { create: true }, }); const query1 = ` diff --git a/packages/graphql/tests/integration/directives/vector/vector-filtering.int.test.ts b/packages/graphql/tests/integration/directives/vector/vector-filtering.int.test.ts index 827fa9aa71..41a14c4b92 100644 --- a/packages/graphql/tests/integration/directives/vector/vector-filtering.int.test.ts +++ b/packages/graphql/tests/integration/directives/vector/vector-filtering.int.test.ts @@ -120,7 +120,6 @@ describe("@vector directive - filtering", () => { await neoSchema.assertIndexesAndConstraints({ driver, sessionConfig: { database: databaseName }, - options: { create: true }, }); }); diff --git a/packages/graphql/tests/integration/directives/vector/vector-pagination.int.test.ts b/packages/graphql/tests/integration/directives/vector/vector-pagination.int.test.ts index 04dcd1a713..a46256cbd6 100644 --- a/packages/graphql/tests/integration/directives/vector/vector-pagination.int.test.ts +++ b/packages/graphql/tests/integration/directives/vector/vector-pagination.int.test.ts @@ -121,7 +121,6 @@ describe("@vector directive - pagination", () => { await neoSchema.assertIndexesAndConstraints({ driver, sessionConfig: { database: databaseName }, - options: { create: true }, }); }); diff --git a/packages/graphql/tests/integration/directives/vector/vector-query.int.test.ts b/packages/graphql/tests/integration/directives/vector/vector-query.int.test.ts index a642edd4db..49d39281e4 100644 --- a/packages/graphql/tests/integration/directives/vector/vector-query.int.test.ts +++ b/packages/graphql/tests/integration/directives/vector/vector-query.int.test.ts @@ -121,7 +121,6 @@ describe("@vector directive - Query", () => { await neoSchema.assertIndexesAndConstraints({ driver, sessionConfig: { database: databaseName }, - options: { create: true }, }); }); diff --git a/packages/graphql/tests/integration/directives/vector/vector-sorting.int.test.ts b/packages/graphql/tests/integration/directives/vector/vector-sorting.int.test.ts index fb3f09b9cb..1020182e12 100644 --- a/packages/graphql/tests/integration/directives/vector/vector-sorting.int.test.ts +++ b/packages/graphql/tests/integration/directives/vector/vector-sorting.int.test.ts @@ -113,7 +113,6 @@ describe("@vector directive - Query", () => { await neoSchema.assertIndexesAndConstraints({ driver, sessionConfig: { database: databaseName }, - options: { create: true }, }); }); diff --git a/packages/graphql/tests/integration/issues/5378.int.test.ts b/packages/graphql/tests/integration/issues/5378.int.test.ts index 0dcdf58478..490dc1682c 100644 --- a/packages/graphql/tests/integration/issues/5378.int.test.ts +++ b/packages/graphql/tests/integration/issues/5378.int.test.ts @@ -64,11 +64,13 @@ describe("https://github.com/neo4j/graphql/issues/5378", () => { typeDefs, }); + await testHelper.createFulltextIndex("fulltext_index_space_name_number", Space.name, ["Name", "Number"]); + await testHelper.createUniqueConstraint("unique_constraint_space_id", Space.name, "Id"); + await neoSchema.getSchema(); await neoSchema.assertIndexesAndConstraints({ driver: await testHelper.getDriver(), sessionConfig: { database: databaseName }, - options: { create: true }, }); }); diff --git a/packages/graphql/tests/utils/tests-helper.ts b/packages/graphql/tests/utils/tests-helper.ts index 0643ca37d8..8ee9d2a7db 100644 --- a/packages/graphql/tests/utils/tests-helper.ts +++ b/packages/graphql/tests/utils/tests-helper.ts @@ -208,6 +208,26 @@ export class TestHelper { return new Neo4jDatabaseInfo(rawVersion, edition); } + public async createFulltextIndex(name: string, label: string, properties: string[]): Promise { + const cypher = [ + `CREATE FULLTEXT INDEX ${name}`, + `IF NOT EXISTS FOR (n:${label})`, + `ON EACH [${properties.map((p) => `n.${p}`).join(", ")}]`, + ].join(" "); + + await this.executeCypher(cypher); + } + + public async createUniqueConstraint(name: string, label: string, property: string): Promise { + const cypher = [ + `CREATE CONSTRAINT ${name}`, + `IF NOT EXISTS FOR (n:${label})`, + `REQUIRE n.${property} IS UNIQUE`, + ].join(" "); + + await this.executeCypher(cypher); + } + private async checkConnectivity(driver: neo4j.Driver): Promise { if (process.env.USE_DEFAULT_DB) { return this.checkConnectivityToDefaultDatabase(driver);