diff --git a/packages/graphql/tests/integration/aggregations/top-level/datetime.int.test.ts b/packages/graphql/tests/integration/aggregations/top-level/datetime.int.test.ts index d8820fd421..7f7c609133 100644 --- a/packages/graphql/tests/integration/aggregations/top-level/datetime.int.test.ts +++ b/packages/graphql/tests/integration/aggregations/top-level/datetime.int.test.ts @@ -17,19 +17,32 @@ * limitations under the License. */ -import type { Driver } from "neo4j-driver"; import { graphql } from "graphql"; +import type { Driver } from "neo4j-driver"; import { generate } from "randomstring"; -import Neo4jHelper from "../../neo4j"; import { Neo4jGraphQL } from "../../../../src/classes"; +import { UniqueType } from "../../../utils/graphql-types"; +import Neo4jHelper from "../../neo4j"; describe("aggregations-top_level-datetime", () => { let driver: Driver; let neo4j: Neo4jHelper; + let typeDefs: string; + let neoSchema: Neo4jGraphQL; + let Movie: UniqueType; beforeAll(async () => { neo4j = new Neo4jHelper(); driver = await neo4j.getDriver(); + Movie = new UniqueType("Movie"); + typeDefs = ` + type ${Movie} { + testString: String + createdAt: DateTime + } + `; + + neoSchema = new Neo4jGraphQL({ typeDefs }); }); afterAll(async () => { @@ -39,13 +52,6 @@ describe("aggregations-top_level-datetime", () => { test("should return the min of node properties", async () => { const session = await neo4j.getSession(); - const typeDefs = ` - type Movie { - testString: String - createdAt: DateTime - } - `; - const testString = generate({ charset: "alphabetic", readable: true, @@ -53,15 +59,13 @@ describe("aggregations-top_level-datetime", () => { const minDate = new Date(); - const neoSchema = new Neo4jGraphQL({ typeDefs }); - try { await session.run( ` - CREATE (:Movie {testString: $testString, createdAt: datetime("${minDate.toISOString()}")}) - CREATE (:Movie {testString: $testString, createdAt: datetime()}) - CREATE (:Movie {testString: $testString, createdAt: datetime()}) - CREATE (:Movie {testString: $testString, createdAt: datetime()}) + CREATE (:${Movie} {testString: $testString, createdAt: datetime("${minDate.toISOString()}")}) + CREATE (:${Movie} {testString: $testString, createdAt: datetime()}) + CREATE (:${Movie} {testString: $testString, createdAt: datetime()}) + CREATE (:${Movie} {testString: $testString, createdAt: datetime()}) `, { testString, @@ -70,7 +74,7 @@ describe("aggregations-top_level-datetime", () => { const query = ` { - moviesAggregate(where: {testString: "${testString}"}) { + ${Movie.operations.aggregate}(where: {testString: "${testString}"}) { createdAt { min } @@ -90,7 +94,7 @@ describe("aggregations-top_level-datetime", () => { expect(gqlResult.errors).toBeUndefined(); - expect((gqlResult.data as any).moviesAggregate).toEqual({ + expect((gqlResult.data as any)[Movie.operations.aggregate]).toEqual({ createdAt: { min: minDate.toISOString(), }, @@ -103,13 +107,6 @@ describe("aggregations-top_level-datetime", () => { test("should return the max of node properties", async () => { const session = await neo4j.getSession(); - const typeDefs = ` - type Movie { - testString: String - createdAt: DateTime - } - `; - const testString = generate({ charset: "alphabetic", readable: true, @@ -120,15 +117,13 @@ describe("aggregations-top_level-datetime", () => { const maxDate = new Date(); maxDate.setDate(maxDate.getDate() + 1); - const neoSchema = new Neo4jGraphQL({ typeDefs }); - try { await session.run( ` - CREATE (:Movie {testString: $testString, createdAt: datetime("${minDate.toISOString()}")}) - CREATE (:Movie {testString: $testString, createdAt: datetime()}) - CREATE (:Movie {testString: $testString, createdAt: datetime()}) - CREATE (:Movie {testString: $testString, createdAt: datetime("${maxDate.toISOString()}")}) + CREATE (:${Movie} {testString: $testString, createdAt: datetime("${minDate.toISOString()}")}) + CREATE (:${Movie} {testString: $testString, createdAt: datetime()}) + CREATE (:${Movie} {testString: $testString, createdAt: datetime()}) + CREATE (:${Movie} {testString: $testString, createdAt: datetime("${maxDate.toISOString()}")}) `, { testString, @@ -137,7 +132,7 @@ describe("aggregations-top_level-datetime", () => { const query = ` { - moviesAggregate(where: {testString: "${testString}"}) { + ${Movie.operations.aggregate}(where: {testString: "${testString}"}) { createdAt { max } @@ -157,7 +152,7 @@ describe("aggregations-top_level-datetime", () => { expect(gqlResult.errors).toBeUndefined(); - expect((gqlResult.data as any).moviesAggregate).toEqual({ + expect((gqlResult.data as any)[Movie.operations.aggregate]).toEqual({ createdAt: { max: maxDate.toISOString(), }, @@ -170,13 +165,6 @@ describe("aggregations-top_level-datetime", () => { test("should return the min and max of node properties", async () => { const session = await neo4j.getSession(); - const typeDefs = ` - type Movie { - testString: String - createdAt: DateTime - } - `; - const testString = generate({ charset: "alphabetic", readable: true, @@ -187,15 +175,13 @@ describe("aggregations-top_level-datetime", () => { const maxDate = new Date(); maxDate.setDate(maxDate.getDate() + 1); - const neoSchema = new Neo4jGraphQL({ typeDefs }); - try { await session.run( ` - CREATE (:Movie {testString: $testString, createdAt: datetime("${minDate.toISOString()}")}) - CREATE (:Movie {testString: $testString, createdAt: datetime()}) - CREATE (:Movie {testString: $testString, createdAt: datetime()}) - CREATE (:Movie {testString: $testString, createdAt: datetime("${maxDate.toISOString()}")}) + CREATE (:${Movie} {testString: $testString, createdAt: datetime("${minDate.toISOString()}")}) + CREATE (:${Movie} {testString: $testString, createdAt: datetime()}) + CREATE (:${Movie} {testString: $testString, createdAt: datetime()}) + CREATE (:${Movie} {testString: $testString, createdAt: datetime("${maxDate.toISOString()}")}) `, { testString, @@ -204,7 +190,7 @@ describe("aggregations-top_level-datetime", () => { const query = ` { - moviesAggregate(where: {testString: "${testString}"}) { + ${Movie.operations.aggregate}(where: {testString: "${testString}"}) { createdAt { min max @@ -225,7 +211,7 @@ describe("aggregations-top_level-datetime", () => { expect(gqlResult.errors).toBeUndefined(); - expect((gqlResult.data as any).moviesAggregate).toEqual({ + expect((gqlResult.data as any)[Movie.operations.aggregate]).toEqual({ createdAt: { min: minDate.toISOString(), max: maxDate.toISOString(), diff --git a/packages/graphql/tests/integration/aggregations/top-level/duration.int.test.ts b/packages/graphql/tests/integration/aggregations/top-level/duration.int.test.ts index 5a40d731a6..856ea4af17 100644 --- a/packages/graphql/tests/integration/aggregations/top-level/duration.int.test.ts +++ b/packages/graphql/tests/integration/aggregations/top-level/duration.int.test.ts @@ -17,20 +17,33 @@ * limitations under the License. */ +import { graphql } from "graphql"; import type { Driver } from "neo4j-driver"; import neo4jDriver from "neo4j-driver"; -import { graphql } from "graphql"; import { generate } from "randomstring"; -import Neo4jHelper from "../../neo4j"; import { Neo4jGraphQL } from "../../../../src/classes"; +import { UniqueType } from "../../../utils/graphql-types"; +import Neo4jHelper from "../../neo4j"; describe("aggregations-top_level-duration", () => { let driver: Driver; let neo4j: Neo4jHelper; + let Movie: UniqueType; + let typeDefs: string; + let neoSchema: Neo4jGraphQL; beforeAll(async () => { neo4j = new Neo4jHelper(); driver = await neo4j.getDriver(); + Movie = new UniqueType("Movie"); + typeDefs = ` + type ${Movie} { + testString: String + runningTime: Duration + } + `; + + neoSchema = new Neo4jGraphQL({ typeDefs }); }); afterAll(async () => { @@ -40,13 +53,6 @@ describe("aggregations-top_level-duration", () => { test("should return the min of node properties", async () => { const session = await neo4j.getSession(); - const typeDefs = ` - type Movie { - testString: String - runningTime: Duration - } - `; - const testString = generate({ charset: "alphabetic", readable: true, @@ -57,13 +63,11 @@ describe("aggregations-top_level-duration", () => { const minDuration = new neo4jDriver.types.Duration(months, days, 0, 0); const maxDuration = new neo4jDriver.types.Duration(months + 1, days, 0, 0); - const neoSchema = new Neo4jGraphQL({ typeDefs }); - try { await session.run( ` - CREATE (:Movie {testString: $testString, runningTime: $minDuration}) - CREATE (:Movie {testString: $testString, runningTime: $maxDuration}) + CREATE (:${Movie} {testString: $testString, runningTime: $minDuration}) + CREATE (:${Movie} {testString: $testString, runningTime: $maxDuration}) `, { testString, @@ -74,7 +78,7 @@ describe("aggregations-top_level-duration", () => { const query = ` { - moviesAggregate(where: {testString: "${testString}"}) { + ${Movie.operations.aggregate}(where: {testString: "${testString}"}) { runningTime { min } @@ -94,7 +98,7 @@ describe("aggregations-top_level-duration", () => { expect(gqlResult.errors).toBeUndefined(); - expect((gqlResult.data as any).moviesAggregate).toEqual({ + expect((gqlResult.data as any)[Movie.operations.aggregate]).toEqual({ runningTime: { min: minDuration.toString(), }, @@ -107,13 +111,6 @@ describe("aggregations-top_level-duration", () => { test("should return the max of node properties", async () => { const session = await neo4j.getSession(); - const typeDefs = ` - type Movie { - testString: String - runningTime: Duration - } - `; - const testString = generate({ charset: "alphabetic", readable: true, @@ -124,13 +121,11 @@ describe("aggregations-top_level-duration", () => { const minDuration = new neo4jDriver.types.Duration(months, days, 0, 0); const maxDuration = new neo4jDriver.types.Duration(months + 1, days, 0, 0); - const neoSchema = new Neo4jGraphQL({ typeDefs }); - try { await session.run( ` - CREATE (:Movie {testString: $testString, runningTime: $minDuration}) - CREATE (:Movie {testString: $testString, runningTime: $maxDuration}) + CREATE (:${Movie} {testString: $testString, runningTime: $minDuration}) + CREATE (:${Movie} {testString: $testString, runningTime: $maxDuration}) `, { testString, @@ -141,7 +136,7 @@ describe("aggregations-top_level-duration", () => { const query = ` { - moviesAggregate(where: {testString: "${testString}"}) { + ${Movie.operations.aggregate}(where: {testString: "${testString}"}) { runningTime { max } @@ -161,7 +156,7 @@ describe("aggregations-top_level-duration", () => { expect(gqlResult.errors).toBeUndefined(); - expect((gqlResult.data as any).moviesAggregate).toEqual({ + expect((gqlResult.data as any)[Movie.operations.aggregate]).toEqual({ runningTime: { max: maxDuration.toString(), }, @@ -174,13 +169,6 @@ describe("aggregations-top_level-duration", () => { test("should return the min and max of node properties", async () => { const session = await neo4j.getSession(); - const typeDefs = ` - type Movie { - testString: String - runningTime: Duration - } - `; - const testString = generate({ charset: "alphabetic", readable: true, @@ -191,13 +179,11 @@ describe("aggregations-top_level-duration", () => { const minDuration = new neo4jDriver.types.Duration(months, days, 0, 0); const maxDuration = new neo4jDriver.types.Duration(months + 1, days, 0, 0); - const neoSchema = new Neo4jGraphQL({ typeDefs }); - try { await session.run( ` - CREATE (:Movie {testString: $testString, runningTime: $minDuration}) - CREATE (:Movie {testString: $testString, runningTime: $maxDuration}) + CREATE (:${Movie} {testString: $testString, runningTime: $minDuration}) + CREATE (:${Movie} {testString: $testString, runningTime: $maxDuration}) `, { testString, @@ -208,7 +194,7 @@ describe("aggregations-top_level-duration", () => { const query = ` { - moviesAggregate(where: {testString: "${testString}"}) { + ${Movie.operations.aggregate}(where: {testString: "${testString}"}) { runningTime { min max @@ -229,7 +215,7 @@ describe("aggregations-top_level-duration", () => { expect(gqlResult.errors).toBeUndefined(); - expect((gqlResult.data as any).moviesAggregate).toEqual({ + expect((gqlResult.data as any)[Movie.operations.aggregate]).toEqual({ runningTime: { min: minDuration.toString(), max: maxDuration.toString(), diff --git a/packages/graphql/tests/integration/aggregations/top-level/float.int.test.ts b/packages/graphql/tests/integration/aggregations/top-level/float.int.test.ts index d6b094e2b0..b300545bfa 100644 --- a/packages/graphql/tests/integration/aggregations/top-level/float.int.test.ts +++ b/packages/graphql/tests/integration/aggregations/top-level/float.int.test.ts @@ -17,19 +17,30 @@ * limitations under the License. */ -import type { Driver } from "neo4j-driver"; import { graphql } from "graphql"; +import type { Driver } from "neo4j-driver"; import { generate } from "randomstring"; -import Neo4jHelper from "../../neo4j"; import { Neo4jGraphQL } from "../../../../src/classes"; +import { UniqueType } from "../../../utils/graphql-types"; +import Neo4jHelper from "../../neo4j"; describe("aggregations-top_level-float", () => { let driver: Driver; let neo4j: Neo4jHelper; + let neoSchema: Neo4jGraphQL; + let Movie: UniqueType; beforeAll(async () => { neo4j = new Neo4jHelper(); driver = await neo4j.getDriver(); + Movie = new UniqueType("Movie"); + const typeDefs = ` + type ${Movie} { + testString: String + imdbRating: Float + } + `; + neoSchema = new Neo4jGraphQL({ typeDefs }); }); afterAll(async () => { @@ -39,27 +50,18 @@ describe("aggregations-top_level-float", () => { test("should return the min of node properties", async () => { const session = await neo4j.getSession(); - const typeDefs = ` - type Movie { - testString: String - imdbRating: Float - } - `; - const testString = generate({ charset: "alphabetic", readable: true, }); - const neoSchema = new Neo4jGraphQL({ typeDefs }); - try { await session.run( ` - CREATE (:Movie {testString: $testString, imdbRating: 1.1}) - CREATE (:Movie {testString: $testString, imdbRating: 2.1}) - CREATE (:Movie {testString: $testString, imdbRating: 3.1}) - CREATE (:Movie {testString: $testString, imdbRating: 4.1}) + CREATE (:${Movie} {testString: $testString, imdbRating: 1.1}) + CREATE (:${Movie} {testString: $testString, imdbRating: 2.1}) + CREATE (:${Movie} {testString: $testString, imdbRating: 3.1}) + CREATE (:${Movie} {testString: $testString, imdbRating: 4.1}) `, { testString, @@ -68,7 +70,7 @@ describe("aggregations-top_level-float", () => { const query = ` { - moviesAggregate(where: {testString: "${testString}"}) { + ${Movie.operations.aggregate}(where: {testString: "${testString}"}) { imdbRating { min } @@ -88,7 +90,7 @@ describe("aggregations-top_level-float", () => { expect(gqlResult.errors).toBeUndefined(); - expect((gqlResult.data as any).moviesAggregate).toEqual({ + expect((gqlResult.data as any)[Movie.operations.aggregate]).toEqual({ imdbRating: { min: expect.closeTo(1.1), }, @@ -101,27 +103,18 @@ describe("aggregations-top_level-float", () => { test("should return the max of node properties", async () => { const session = await neo4j.getSession(); - const typeDefs = ` - type Movie { - testString: String - imdbRating: Float - } - `; - const testString = generate({ charset: "alphabetic", readable: true, }); - const neoSchema = new Neo4jGraphQL({ typeDefs }); - try { await session.run( ` - CREATE (:Movie {testString: $testString, imdbRating: 1.1}) - CREATE (:Movie {testString: $testString, imdbRating: 2.1}) - CREATE (:Movie {testString: $testString, imdbRating: 3.1}) - CREATE (:Movie {testString: $testString, imdbRating: 4.1}) + CREATE (:${Movie} {testString: $testString, imdbRating: 1.1}) + CREATE (:${Movie} {testString: $testString, imdbRating: 2.1}) + CREATE (:${Movie} {testString: $testString, imdbRating: 3.1}) + CREATE (:${Movie} {testString: $testString, imdbRating: 4.1}) `, { testString, @@ -130,7 +123,7 @@ describe("aggregations-top_level-float", () => { const query = ` { - moviesAggregate(where: {testString: "${testString}"}) { + ${Movie.operations.aggregate}(where: {testString: "${testString}"}) { imdbRating { max } @@ -150,7 +143,7 @@ describe("aggregations-top_level-float", () => { expect(gqlResult.errors).toBeUndefined(); - expect((gqlResult.data as any).moviesAggregate).toEqual({ + expect((gqlResult.data as any)[Movie.operations.aggregate]).toEqual({ imdbRating: { max: expect.closeTo(4.1), }, @@ -163,27 +156,18 @@ describe("aggregations-top_level-float", () => { test("should return the average of node properties", async () => { const session = await neo4j.getSession(); - const typeDefs = ` - type Movie { - testString: String - imdbRating: Float - } - `; - const testString = generate({ charset: "alphabetic", readable: true, }); - const neoSchema = new Neo4jGraphQL({ typeDefs }); - try { await session.run( ` - CREATE (:Movie {testString: $testString, imdbRating: 1.1}) - CREATE (:Movie {testString: $testString, imdbRating: 2.1}) - CREATE (:Movie {testString: $testString, imdbRating: 3.1}) - CREATE (:Movie {testString: $testString, imdbRating: 4.1}) + CREATE (:${Movie} {testString: $testString, imdbRating: 1.1}) + CREATE (:${Movie} {testString: $testString, imdbRating: 2.1}) + CREATE (:${Movie} {testString: $testString, imdbRating: 3.1}) + CREATE (:${Movie} {testString: $testString, imdbRating: 4.1}) `, { testString, @@ -192,7 +176,7 @@ describe("aggregations-top_level-float", () => { const query = ` { - moviesAggregate(where: {testString: "${testString}"}) { + ${Movie.operations.aggregate}(where: {testString: "${testString}"}) { imdbRating { average } @@ -212,7 +196,7 @@ describe("aggregations-top_level-float", () => { expect(gqlResult.errors).toBeUndefined(); - expect((gqlResult.data as any).moviesAggregate).toEqual({ + expect((gqlResult.data as any)[Movie.operations.aggregate]).toEqual({ imdbRating: { average: expect.closeTo(2.6), }, @@ -225,27 +209,18 @@ describe("aggregations-top_level-float", () => { test("should return the sum of node properties", async () => { const session = await neo4j.getSession(); - const typeDefs = ` - type Movie { - testString: String - imdbRating: Float - } - `; - const testString = generate({ charset: "alphabetic", readable: true, }); - const neoSchema = new Neo4jGraphQL({ typeDefs }); - try { await session.run( ` - CREATE (:Movie {testString: $testString, imdbRating: 1.1}) - CREATE (:Movie {testString: $testString, imdbRating: 2.1}) - CREATE (:Movie {testString: $testString, imdbRating: 3.1}) - CREATE (:Movie {testString: $testString, imdbRating: 4.1}) + CREATE (:${Movie} {testString: $testString, imdbRating: 1.1}) + CREATE (:${Movie} {testString: $testString, imdbRating: 2.1}) + CREATE (:${Movie} {testString: $testString, imdbRating: 3.1}) + CREATE (:${Movie} {testString: $testString, imdbRating: 4.1}) `, { testString, @@ -254,7 +229,7 @@ describe("aggregations-top_level-float", () => { const query = ` { - moviesAggregate(where: {testString: "${testString}"}) { + ${Movie.operations.aggregate}(where: {testString: "${testString}"}) { imdbRating { sum } @@ -274,7 +249,7 @@ describe("aggregations-top_level-float", () => { expect(gqlResult.errors).toBeUndefined(); - expect((gqlResult.data as any).moviesAggregate).toEqual({ + expect((gqlResult.data as any)[Movie.operations.aggregate]).toEqual({ imdbRating: { sum: expect.closeTo(10.4), }, @@ -287,27 +262,18 @@ describe("aggregations-top_level-float", () => { test("should return the min, max, sum and average of node properties", async () => { const session = await neo4j.getSession(); - const typeDefs = ` - type Movie { - testString: String - imdbRating: Float - } - `; - const testString = generate({ charset: "alphabetic", readable: true, }); - const neoSchema = new Neo4jGraphQL({ typeDefs }); - try { await session.run( ` - CREATE (:Movie {testString: $testString, imdbRating: 1.1}) - CREATE (:Movie {testString: $testString, imdbRating: 2.1}) - CREATE (:Movie {testString: $testString, imdbRating: 3.1}) - CREATE (:Movie {testString: $testString, imdbRating: 4.1}) + CREATE (:${Movie} {testString: $testString, imdbRating: 1.1}) + CREATE (:${Movie} {testString: $testString, imdbRating: 2.1}) + CREATE (:${Movie} {testString: $testString, imdbRating: 3.1}) + CREATE (:${Movie} {testString: $testString, imdbRating: 4.1}) `, { testString, @@ -316,7 +282,7 @@ describe("aggregations-top_level-float", () => { const query = ` { - moviesAggregate(where: {testString: "${testString}"}) { + ${Movie.operations.aggregate}(where: {testString: "${testString}"}) { imdbRating { min max @@ -339,7 +305,7 @@ describe("aggregations-top_level-float", () => { expect(gqlResult.errors).toBeUndefined(); - expect((gqlResult.data as any).moviesAggregate).toEqual({ + expect((gqlResult.data as any)[Movie.operations.aggregate]).toEqual({ imdbRating: { min: expect.closeTo(1.1), max: expect.closeTo(4.1), diff --git a/packages/graphql/tests/integration/aggregations/top-level/id.int.test.ts b/packages/graphql/tests/integration/aggregations/top-level/id.int.test.ts index 18933d9802..3905a49e2c 100644 --- a/packages/graphql/tests/integration/aggregations/top-level/id.int.test.ts +++ b/packages/graphql/tests/integration/aggregations/top-level/id.int.test.ts @@ -17,19 +17,31 @@ * limitations under the License. */ -import type { Driver } from "neo4j-driver"; import { graphql } from "graphql"; +import type { Driver } from "neo4j-driver"; import { generate } from "randomstring"; -import Neo4jHelper from "../../neo4j"; import { Neo4jGraphQL } from "../../../../src/classes"; +import { UniqueType } from "../../../utils/graphql-types"; +import Neo4jHelper from "../../neo4j"; describe("aggregations-top_level-id", () => { let driver: Driver; let neo4j: Neo4jHelper; + let Movie: UniqueType; + let neoSchema: Neo4jGraphQL; beforeAll(async () => { neo4j = new Neo4jHelper(); driver = await neo4j.getDriver(); + Movie = new UniqueType("Movie"); + const typeDefs = ` + type ${Movie} { + testId: ID + id: ID + } + `; + + neoSchema = new Neo4jGraphQL({ typeDefs }); }); afterAll(async () => { @@ -39,27 +51,18 @@ describe("aggregations-top_level-id", () => { test("should return the shortest of node properties", async () => { const session = await neo4j.getSession(); - const typeDefs = ` - type Movie { - testId: ID - id: ID - } - `; - const id = generate({ charset: "alphabetic", readable: true, }); - const neoSchema = new Neo4jGraphQL({ typeDefs }); - try { await session.run( ` - CREATE (:Movie {testId: $id, id: "1"}) - CREATE (:Movie {testId: $id, id: "22"}) - CREATE (:Movie {testId: $id, id: "333"}) - CREATE (:Movie {testId: $id, id: "4444"}) + CREATE (:${Movie} {testId: $id, id: "1"}) + CREATE (:${Movie} {testId: $id, id: "22"}) + CREATE (:${Movie} {testId: $id, id: "333"}) + CREATE (:${Movie} {testId: $id, id: "4444"}) `, { id, @@ -68,7 +71,7 @@ describe("aggregations-top_level-id", () => { const query = ` { - moviesAggregate(where: {testId: "${id}"}) { + ${Movie.operations.aggregate}(where: {testId: "${id}"}) { id { shortest } @@ -88,7 +91,7 @@ describe("aggregations-top_level-id", () => { expect(gqlResult.errors).toBeUndefined(); - expect((gqlResult.data as any).moviesAggregate).toEqual({ + expect((gqlResult.data as any)[Movie.operations.aggregate]).toEqual({ id: { shortest: "1", }, @@ -101,27 +104,18 @@ describe("aggregations-top_level-id", () => { test("should return the longest of node properties", async () => { const session = await neo4j.getSession(); - const typeDefs = ` - type Movie { - testId: ID - id: ID - } - `; - const id = generate({ charset: "alphabetic", readable: true, }); - const neoSchema = new Neo4jGraphQL({ typeDefs }); - try { await session.run( ` - CREATE (:Movie {testId: $id, id: "1"}) - CREATE (:Movie {testId: $id, id: "22"}) - CREATE (:Movie {testId: $id, id: "333"}) - CREATE (:Movie {testId: $id, id: "4444"}) + CREATE (:${Movie} {testId: $id, id: "1"}) + CREATE (:${Movie} {testId: $id, id: "22"}) + CREATE (:${Movie} {testId: $id, id: "333"}) + CREATE (:${Movie} {testId: $id, id: "4444"}) `, { id, @@ -130,7 +124,7 @@ describe("aggregations-top_level-id", () => { const query = ` { - moviesAggregate(where: {testId: "${id}"}) { + ${Movie.operations.aggregate}(where: {testId: "${id}"}) { id { longest } @@ -150,7 +144,7 @@ describe("aggregations-top_level-id", () => { expect(gqlResult.errors).toBeUndefined(); - expect((gqlResult.data as any).moviesAggregate).toEqual({ + expect((gqlResult.data as any)[Movie.operations.aggregate]).toEqual({ id: { longest: "4444", }, @@ -163,27 +157,18 @@ describe("aggregations-top_level-id", () => { test("should return the shortest and longest of node properties", async () => { const session = await neo4j.getSession(); - const typeDefs = ` - type Movie { - testId: ID - id: ID - } - `; - const id = generate({ charset: "alphabetic", readable: true, }); - const neoSchema = new Neo4jGraphQL({ typeDefs }); - try { await session.run( ` - CREATE (:Movie {testId: $id, id: "1"}) - CREATE (:Movie {testId: $id, id: "22"}) - CREATE (:Movie {testId: $id, id: "333"}) - CREATE (:Movie {testId: $id, id: "4444"}) + CREATE (:${Movie} {testId: $id, id: "1"}) + CREATE (:${Movie} {testId: $id, id: "22"}) + CREATE (:${Movie} {testId: $id, id: "333"}) + CREATE (:${Movie} {testId: $id, id: "4444"}) `, { id, @@ -192,7 +177,7 @@ describe("aggregations-top_level-id", () => { const query = ` { - moviesAggregate(where: {testId: "${id}"}) { + ${Movie.operations.aggregate}(where: {testId: "${id}"}) { id { shortest longest @@ -213,7 +198,7 @@ describe("aggregations-top_level-id", () => { expect(gqlResult.errors).toBeUndefined(); - expect((gqlResult.data as any).moviesAggregate).toEqual({ + expect((gqlResult.data as any)[Movie.operations.aggregate]).toEqual({ id: { shortest: "1", longest: "4444", diff --git a/packages/graphql/tests/integration/aggregations/top-level/int.int.test.ts b/packages/graphql/tests/integration/aggregations/top-level/int.int.test.ts index 8fd4ab9937..a63bc34ae4 100644 --- a/packages/graphql/tests/integration/aggregations/top-level/int.int.test.ts +++ b/packages/graphql/tests/integration/aggregations/top-level/int.int.test.ts @@ -17,19 +17,31 @@ * limitations under the License. */ -import type { Driver } from "neo4j-driver"; import { graphql } from "graphql"; +import type { Driver } from "neo4j-driver"; import { generate } from "randomstring"; -import Neo4jHelper from "../../neo4j"; import { Neo4jGraphQL } from "../../../../src/classes"; +import { UniqueType } from "../../../utils/graphql-types"; +import Neo4jHelper from "../../neo4j"; describe("aggregations-top_level-int", () => { let driver: Driver; let neo4j: Neo4jHelper; + let neoSchema: Neo4jGraphQL; + let Movie: UniqueType; beforeAll(async () => { neo4j = new Neo4jHelper(); driver = await neo4j.getDriver(); + Movie = new UniqueType("Movie"); + const typeDefs = ` + type ${Movie} { + testString: String + imdbRating: Int + } + `; + + neoSchema = new Neo4jGraphQL({ typeDefs }); }); afterAll(async () => { @@ -39,27 +51,18 @@ describe("aggregations-top_level-int", () => { test("should return the min of node properties", async () => { const session = await neo4j.getSession(); - const typeDefs = ` - type Movie { - testString: String - imdbRating: Int - } - `; - const testString = generate({ charset: "alphabetic", readable: true, }); - const neoSchema = new Neo4jGraphQL({ typeDefs }); - try { await session.run( ` - CREATE (:Movie {testString: $testString, imdbRating: 1}) - CREATE (:Movie {testString: $testString, imdbRating: 2}) - CREATE (:Movie {testString: $testString, imdbRating: 3}) - CREATE (:Movie {testString: $testString, imdbRating: 4}) + CREATE (:${Movie} {testString: $testString, imdbRating: 1}) + CREATE (:${Movie} {testString: $testString, imdbRating: 2}) + CREATE (:${Movie} {testString: $testString, imdbRating: 3}) + CREATE (:${Movie} {testString: $testString, imdbRating: 4}) `, { testString, @@ -68,7 +71,7 @@ describe("aggregations-top_level-int", () => { const query = ` { - moviesAggregate(where: {testString: "${testString}"}) { + ${Movie.operations.aggregate}(where: {testString: "${testString}"}) { imdbRating { min } @@ -88,7 +91,7 @@ describe("aggregations-top_level-int", () => { expect(gqlResult.errors).toBeUndefined(); - expect((gqlResult.data as any).moviesAggregate).toEqual({ + expect((gqlResult.data as any)[Movie.operations.aggregate]).toEqual({ imdbRating: { min: 1, }, @@ -101,27 +104,18 @@ describe("aggregations-top_level-int", () => { test("should return the max of node properties", async () => { const session = await neo4j.getSession(); - const typeDefs = ` - type Movie { - testString: String - imdbRating: Int - } - `; - const testString = generate({ charset: "alphabetic", readable: true, }); - const neoSchema = new Neo4jGraphQL({ typeDefs }); - try { await session.run( ` - CREATE (:Movie {testString: $testString, imdbRating: 1}) - CREATE (:Movie {testString: $testString, imdbRating: 2}) - CREATE (:Movie {testString: $testString, imdbRating: 3}) - CREATE (:Movie {testString: $testString, imdbRating: 4}) + CREATE (:${Movie} {testString: $testString, imdbRating: 1}) + CREATE (:${Movie} {testString: $testString, imdbRating: 2}) + CREATE (:${Movie} {testString: $testString, imdbRating: 3}) + CREATE (:${Movie} {testString: $testString, imdbRating: 4}) `, { testString, @@ -130,7 +124,7 @@ describe("aggregations-top_level-int", () => { const query = ` { - moviesAggregate(where: {testString: "${testString}"}) { + ${Movie.operations.aggregate}(where: {testString: "${testString}"}) { imdbRating { max } @@ -150,7 +144,7 @@ describe("aggregations-top_level-int", () => { expect(gqlResult.errors).toBeUndefined(); - expect((gqlResult.data as any).moviesAggregate).toEqual({ + expect((gqlResult.data as any)[Movie.operations.aggregate]).toEqual({ imdbRating: { max: 4, }, @@ -163,27 +157,18 @@ describe("aggregations-top_level-int", () => { test("should return the average of node properties", async () => { const session = await neo4j.getSession(); - const typeDefs = ` - type Movie { - testString: String - imdbRating: Int - } - `; - const testString = generate({ charset: "alphabetic", readable: true, }); - const neoSchema = new Neo4jGraphQL({ typeDefs }); - try { await session.run( ` - CREATE (:Movie {testString: $testString, imdbRating: 1}) - CREATE (:Movie {testString: $testString, imdbRating: 2}) - CREATE (:Movie {testString: $testString, imdbRating: 3}) - CREATE (:Movie {testString: $testString, imdbRating: 4}) + CREATE (:${Movie} {testString: $testString, imdbRating: 1}) + CREATE (:${Movie} {testString: $testString, imdbRating: 2}) + CREATE (:${Movie} {testString: $testString, imdbRating: 3}) + CREATE (:${Movie} {testString: $testString, imdbRating: 4}) `, { testString, @@ -192,7 +177,7 @@ describe("aggregations-top_level-int", () => { const query = ` { - moviesAggregate(where: {testString: "${testString}"}) { + ${Movie.operations.aggregate}(where: {testString: "${testString}"}) { imdbRating { average } @@ -212,7 +197,7 @@ describe("aggregations-top_level-int", () => { expect(gqlResult.errors).toBeUndefined(); - expect((gqlResult.data as any).moviesAggregate).toEqual({ + expect((gqlResult.data as any)[Movie.operations.aggregate]).toEqual({ imdbRating: { average: 2.5, }, @@ -225,27 +210,18 @@ describe("aggregations-top_level-int", () => { test("should return the sum of node properties", async () => { const session = await neo4j.getSession(); - const typeDefs = ` - type Movie { - testString: String - imdbRating: Int - } - `; - const testString = generate({ charset: "alphabetic", readable: true, }); - const neoSchema = new Neo4jGraphQL({ typeDefs }); - try { await session.run( ` - CREATE (:Movie {testString: $testString, imdbRating: 1}) - CREATE (:Movie {testString: $testString, imdbRating: 2}) - CREATE (:Movie {testString: $testString, imdbRating: 3}) - CREATE (:Movie {testString: $testString, imdbRating: 4}) + CREATE (:${Movie} {testString: $testString, imdbRating: 1}) + CREATE (:${Movie} {testString: $testString, imdbRating: 2}) + CREATE (:${Movie} {testString: $testString, imdbRating: 3}) + CREATE (:${Movie} {testString: $testString, imdbRating: 4}) `, { testString, @@ -254,7 +230,7 @@ describe("aggregations-top_level-int", () => { const query = ` { - moviesAggregate(where: {testString: "${testString}"}) { + ${Movie.operations.aggregate}(where: {testString: "${testString}"}) { imdbRating { sum } @@ -274,7 +250,7 @@ describe("aggregations-top_level-int", () => { expect(gqlResult.errors).toBeUndefined(); - expect((gqlResult.data as any).moviesAggregate).toEqual({ + expect((gqlResult.data as any)[Movie.operations.aggregate]).toEqual({ imdbRating: { sum: 10, }, @@ -287,27 +263,18 @@ describe("aggregations-top_level-int", () => { test("should return the min, max, sum and average of node properties", async () => { const session = await neo4j.getSession(); - const typeDefs = ` - type Movie { - testString: String - imdbRating: Int - } - `; - const testString = generate({ charset: "alphabetic", readable: true, }); - const neoSchema = new Neo4jGraphQL({ typeDefs }); - try { await session.run( ` - CREATE (:Movie {testString: $testString, imdbRating: 1}) - CREATE (:Movie {testString: $testString, imdbRating: 2}) - CREATE (:Movie {testString: $testString, imdbRating: 3}) - CREATE (:Movie {testString: $testString, imdbRating: 4}) + CREATE (:${Movie} {testString: $testString, imdbRating: 1}) + CREATE (:${Movie} {testString: $testString, imdbRating: 2}) + CREATE (:${Movie} {testString: $testString, imdbRating: 3}) + CREATE (:${Movie} {testString: $testString, imdbRating: 4}) `, { testString, @@ -316,7 +283,7 @@ describe("aggregations-top_level-int", () => { const query = ` { - moviesAggregate(where: {testString: "${testString}"}) { + ${Movie.operations.aggregate}(where: {testString: "${testString}"}) { imdbRating { min max @@ -339,7 +306,7 @@ describe("aggregations-top_level-int", () => { expect(gqlResult.errors).toBeUndefined(); - expect((gqlResult.data as any).moviesAggregate).toEqual({ + expect((gqlResult.data as any)[Movie.operations.aggregate]).toEqual({ imdbRating: { min: 1, max: 4, diff --git a/packages/graphql/tests/integration/aggregations/where/count.int.test.ts b/packages/graphql/tests/integration/aggregations/where/count.int.test.ts index 987063f105..4ce0dea20d 100644 --- a/packages/graphql/tests/integration/aggregations/where/count.int.test.ts +++ b/packages/graphql/tests/integration/aggregations/where/count.int.test.ts @@ -17,57 +17,62 @@ * limitations under the License. */ -import type { Driver } from "neo4j-driver"; import { graphql } from "graphql"; +import type { Driver } from "neo4j-driver"; import { generate } from "randomstring"; -import Neo4jHelper from "../../neo4j"; import { Neo4jGraphQL } from "../../../../src/classes"; +import { UniqueType } from "../../../utils/graphql-types"; +import Neo4jHelper from "../../neo4j"; describe("aggregations-where-count", () => { let driver: Driver; let neo4j: Neo4jHelper; + let User: UniqueType; + let Post: UniqueType; + let neoSchema: Neo4jGraphQL; beforeAll(async () => { neo4j = new Neo4jHelper(); driver = await neo4j.getDriver(); - }); - - afterAll(async () => { - await driver.close(); - }); - - test("should return posts where the count of likes equal one", async () => { - const session = await neo4j.getSession(); + User = new UniqueType("User"); + Post = new UniqueType("Post"); const typeDefs = ` - type User { + type ${User} { testString: String! } - type Post { + type ${Post} { testString: String! - likes: [User!]! @relationship(type: "LIKES", direction: IN) + likes: [${User}!]! @relationship(type: "LIKES", direction: IN) } `; + neoSchema = new Neo4jGraphQL({ typeDefs }); + }); + + afterAll(async () => { + await driver.close(); + }); + + test("should return posts where the count of likes equal one", async () => { + const session = await neo4j.getSession(); const testString = generate({ charset: "alphabetic", readable: true, }); - const neoSchema = new Neo4jGraphQL({ typeDefs }); - try { await session.run( ` - CREATE (:Post {testString: "${testString}"})<-[:LIKES]-(:User {testString: "${testString}"}) - CREATE (:Post {testString: "${testString}"}) + CREATE (:${Post} {testString: "${testString}"})<-[:LIKES]-(:${User} {testString: "${testString}"}) + CREATE (:${Post} {testString: "${testString}"}) ` ); const query = ` { - posts(where: { testString: "${testString}", likesAggregate: { count: 1 } }) { + ${Post.plural}(where: { testString: "${testString}", likesAggregate: { count: 1 } }) { testString likes { testString @@ -88,7 +93,7 @@ describe("aggregations-where-count", () => { expect(gqlResult.errors).toBeUndefined(); - expect((gqlResult.data as any).posts).toEqual([ + expect((gqlResult.data as any)[Post.plural]).toEqual([ { testString, likes: [{ testString }], @@ -102,35 +107,22 @@ describe("aggregations-where-count", () => { test("should return posts where the count of likes LT one", async () => { const session = await neo4j.getSession(); - const typeDefs = ` - type User { - testString: String! - } - - type Post { - testString: String! - likes: [User!]! @relationship(type: "LIKES", direction: IN) - } - `; - const testString = generate({ charset: "alphabetic", readable: true, }); - const neoSchema = new Neo4jGraphQL({ typeDefs }); - try { await session.run( ` - CREATE (:Post {testString: "${testString}"})<-[:LIKES]-(:User {testString: "${testString}"}) - CREATE (:Post {testString: "${testString}"}) + CREATE (:${Post} {testString: "${testString}"})<-[:LIKES]-(:${User} {testString: "${testString}"}) + CREATE (:${Post} {testString: "${testString}"}) ` ); const query = ` { - posts(where: { testString: "${testString}", likesAggregate: { count_LT: 1 } }) { + ${Post.plural}(where: { testString: "${testString}", likesAggregate: { count_LT: 1 } }) { testString likes { testString @@ -151,7 +143,7 @@ describe("aggregations-where-count", () => { expect(gqlResult.errors).toBeUndefined(); - expect((gqlResult.data as any).posts).toEqual([ + expect((gqlResult.data as any)[Post.plural]).toEqual([ { testString, likes: [], @@ -165,35 +157,22 @@ describe("aggregations-where-count", () => { test("should return posts where the count of likes LTE one", async () => { const session = await neo4j.getSession(); - const typeDefs = ` - type User { - testString: String! - } - - type Post { - testString: String! - likes: [User!]! @relationship(type: "LIKES", direction: IN) - } - `; - const testString = generate({ charset: "alphabetic", readable: true, }); - const neoSchema = new Neo4jGraphQL({ typeDefs }); - try { await session.run( ` - CREATE (:Post {testString: "${testString}"})<-[:LIKES]-(:User {testString: "${testString}"}) - CREATE (:Post {testString: "${testString}"}) + CREATE (:${Post} {testString: "${testString}"})<-[:LIKES]-(:${User} {testString: "${testString}"}) + CREATE (:${Post} {testString: "${testString}"}) ` ); const query = ` { - posts(where: { testString: "${testString}", likesAggregate: { count_LTE: 1 } }) { + ${Post.plural}(where: { testString: "${testString}", likesAggregate: { count_LTE: 1 } }) { testString likes { testString @@ -214,7 +193,7 @@ describe("aggregations-where-count", () => { expect(gqlResult.errors).toBeUndefined(); - expect((gqlResult.data as any).posts).toIncludeSameMembers([ + expect((gqlResult.data as any)[Post.plural]).toIncludeSameMembers([ { testString, likes: [{ testString }], @@ -232,36 +211,23 @@ describe("aggregations-where-count", () => { test("should return posts where the count of likes GT one, regardless of number of likes over 1", async () => { const session = await neo4j.getSession(); - const typeDefs = ` - type User { - testString: String! - } - - type Post { - testString: String! - likes: [User!]! @relationship(type: "LIKES", direction: IN) - } - `; - const testString = generate({ charset: "alphabetic", readable: true, }); - const neoSchema = new Neo4jGraphQL({ typeDefs }); - try { await session.run( ` - CREATE (p:Post {testString: "${testString}"})<-[:LIKES]-(:User {testString: "${testString}"}) - CREATE (p)<-[:LIKES]-(:User {testString: "${testString}"}) - CREATE (:Post {testString: "${testString}"}) + CREATE (p:${Post} {testString: "${testString}"})<-[:LIKES]-(:${User} {testString: "${testString}"}) + CREATE (p)<-[:LIKES]-(:${User} {testString: "${testString}"}) + CREATE (:${Post} {testString: "${testString}"}) ` ); const query = ` { - posts(where: { testString: "${testString}", likesAggregate: { count_GT: 1 } }) { + ${Post.plural}(where: { testString: "${testString}", likesAggregate: { count_GT: 1 } }) { testString likes { testString @@ -282,7 +248,7 @@ describe("aggregations-where-count", () => { expect(gqlResult.errors).toBeUndefined(); - expect((gqlResult.data as any).posts).toEqual([ + expect((gqlResult.data as any)[Post.plural]).toEqual([ { testString, likes: [{ testString }, { testString }], @@ -296,35 +262,22 @@ describe("aggregations-where-count", () => { test("should return posts where the count of likes GT one", async () => { const session = await neo4j.getSession(); - const typeDefs = ` - type User { - testString: String! - } - - type Post { - testString: String! - likes: [User!]! @relationship(type: "LIKES", direction: IN) - } - `; - const testString = generate({ charset: "alphabetic", readable: true, }); - const neoSchema = new Neo4jGraphQL({ typeDefs }); - try { await session.run( ` - CREATE (:Post {testString: "${testString}"})<-[:LIKES]-(:User {testString: "${testString}"}) - CREATE (:Post {testString: "${testString}"}) + CREATE (:${Post} {testString: "${testString}"})<-[:LIKES]-(:${User} {testString: "${testString}"}) + CREATE (:${Post} {testString: "${testString}"}) ` ); const query = ` { - posts(where: { testString: "${testString}", likesAggregate: { count_GTE: 1 } }) { + ${Post.plural}(where: { testString: "${testString}", likesAggregate: { count_GTE: 1 } }) { testString likes { testString @@ -345,7 +298,7 @@ describe("aggregations-where-count", () => { expect(gqlResult.errors).toBeUndefined(); - expect((gqlResult.data as any).posts).toEqual([ + expect((gqlResult.data as any)[Post.plural]).toEqual([ { testString, likes: [{ testString }], diff --git a/packages/graphql/tests/integration/aggregations/where/edge/bigint.int.test.ts b/packages/graphql/tests/integration/aggregations/where/edge/bigint.int.test.ts index 1fc425f5d5..cdc2048e0e 100644 --- a/packages/graphql/tests/integration/aggregations/where/edge/bigint.int.test.ts +++ b/packages/graphql/tests/integration/aggregations/where/edge/bigint.int.test.ts @@ -21,34 +21,32 @@ import { graphql } from "graphql"; import type { Driver } from "neo4j-driver"; import { generate } from "randomstring"; import { Neo4jGraphQL } from "../../../../../src/classes"; +import { UniqueType } from "../../../../utils/graphql-types"; import Neo4jHelper from "../../../neo4j"; describe("aggregations-where-edge-bigint", () => { let driver: Driver; let neo4j: Neo4jHelper; - - const bigInt = "2147483647"; + let neoSchema: Neo4jGraphQL; + let bigInt: string; + let User: UniqueType; + let Post: UniqueType; beforeAll(async () => { neo4j = new Neo4jHelper(); driver = await neo4j.getDriver(); - }); - - afterAll(async () => { - await driver.close(); - }); - - test("should return posts where a edge like BigInt is EQUAL to", async () => { - const session = await neo4j.getSession(); + bigInt = "2147483647"; + User = new UniqueType("User"); + Post = new UniqueType("Post"); const typeDefs = ` - type User { + type ${User} { testString: String! } - type Post { - testString: String! - likes: [User!]! @relationship(type: "LIKES", direction: IN, properties: "Likes") + type ${Post} { + testString: String! + likes: [${User}!]! @relationship(type: "LIKES", direction: IN, properties: "Likes") } type Likes @relationshipProperties { @@ -56,24 +54,32 @@ describe("aggregations-where-edge-bigint", () => { } `; + neoSchema = new Neo4jGraphQL({ typeDefs }); + }); + + afterAll(async () => { + await driver.close(); + }); + + test("should return posts where a edge like BigInt is EQUAL to", async () => { + const session = await neo4j.getSession(); + const testString = generate({ charset: "alphabetic", readable: true, }); - const neoSchema = new Neo4jGraphQL({ typeDefs }); - try { await session.run( ` - CREATE (:Post {testString: "${testString}"})<-[:LIKES {someBigInt: toInteger(${bigInt})}]-(:User {testString: "${testString}"}) - CREATE (:Post {testString: "${testString}"}) + CREATE (:${Post} {testString: "${testString}"})<-[:LIKES {someBigInt: toInteger(${bigInt})}]-(:${User} {testString: "${testString}"}) + CREATE (:${Post} {testString: "${testString}"}) ` ); const query = ` { - posts(where: { testString: "${testString}", likesAggregate: { edge: { someBigInt_EQUAL: ${bigInt} } } }) { + ${Post.plural}(where: { testString: "${testString}", likesAggregate: { edge: { someBigInt_EQUAL: ${bigInt} } } }) { testString likes { testString @@ -94,7 +100,7 @@ describe("aggregations-where-edge-bigint", () => { expect(gqlResult.errors).toBeUndefined(); - expect((gqlResult.data as any).posts).toEqual([ + expect((gqlResult.data as any)[Post.plural]).toEqual([ { testString, likes: [{ testString }], @@ -108,21 +114,6 @@ describe("aggregations-where-edge-bigint", () => { test("should return posts where a edge like BigInt is GT than", async () => { const session = await neo4j.getSession(); - const typeDefs = ` - type User { - testString: String! - } - - type Post { - testString: String! - likes: [User!]! @relationship(type: "LIKES", direction: IN, properties: "Likes") - } - - type Likes @relationshipProperties { - someBigInt: BigInt - } - `; - const testString = generate({ charset: "alphabetic", readable: true, @@ -131,19 +122,17 @@ describe("aggregations-where-edge-bigint", () => { const someBigInt = `${bigInt}1`; const someBigIntGt = bigInt.substring(0, bigInt.length - 1); - const neoSchema = new Neo4jGraphQL({ typeDefs }); - try { await session.run( ` - CREATE (:Post {testString: "${testString}"})<-[:LIKES {someBigInt: ${someBigInt}}]-(:User {testString: "${testString}"}) - CREATE (:Post {testString: "${testString}"}) + CREATE (:${Post} {testString: "${testString}"})<-[:LIKES {someBigInt: ${someBigInt}}]-(:${User} {testString: "${testString}"}) + CREATE (:${Post} {testString: "${testString}"}) ` ); const query = ` { - posts(where: { testString: "${testString}", likesAggregate: { edge: { someBigInt_GT: ${someBigIntGt} } } }) { + ${Post.plural}(where: { testString: "${testString}", likesAggregate: { edge: { someBigInt_GT: ${someBigIntGt} } } }) { testString likes { testString @@ -164,7 +153,7 @@ describe("aggregations-where-edge-bigint", () => { expect(gqlResult.errors).toBeUndefined(); - expect((gqlResult.data as any).posts).toEqual([ + expect((gqlResult.data as any)[Post.plural]).toEqual([ { testString, likes: [{ testString }], @@ -178,39 +167,22 @@ describe("aggregations-where-edge-bigint", () => { test("should return posts where a edge like BigInt is GTE than", async () => { const session = await neo4j.getSession(); - const typeDefs = ` - type User { - testString: String! - } - - type Post { - testString: String! - likes: [User!]! @relationship(type: "LIKES", direction: IN, properties: "Likes") - } - - type Likes @relationshipProperties { - someBigInt: BigInt - } - `; - const testString = generate({ charset: "alphabetic", readable: true, }); - const neoSchema = new Neo4jGraphQL({ typeDefs }); - try { await session.run( ` - CREATE (:Post {testString: "${testString}"})<-[:LIKES {someBigInt: toInteger(${bigInt})}]-(:User {testString: "${testString}"}) - CREATE (:Post {testString: "${testString}"}) + CREATE (:${Post} {testString: "${testString}"})<-[:LIKES {someBigInt: toInteger(${bigInt})}]-(:${User} {testString: "${testString}"}) + CREATE (:${Post} {testString: "${testString}"}) ` ); const query = ` { - posts(where: { testString: "${testString}", likesAggregate: { edge: { someBigInt_GTE: ${bigInt} } } }) { + ${Post.plural}(where: { testString: "${testString}", likesAggregate: { edge: { someBigInt_GTE: ${bigInt} } } }) { testString likes { testString @@ -231,7 +203,7 @@ describe("aggregations-where-edge-bigint", () => { expect(gqlResult.errors).toBeUndefined(); - expect((gqlResult.data as any).posts).toEqual([ + expect((gqlResult.data as any)[Post.plural]).toEqual([ { testString, likes: [{ testString }], @@ -245,21 +217,6 @@ describe("aggregations-where-edge-bigint", () => { test("should return posts where a edge like BigInt is LT than", async () => { const session = await neo4j.getSession(); - const typeDefs = ` - type User { - testString: String! - } - - type Post { - testString: String! - likes: [User!]! @relationship(type: "LIKES", direction: IN, properties: "Likes") - } - - type Likes @relationshipProperties { - someBigInt: BigInt - } - `; - const testString = generate({ charset: "alphabetic", readable: true, @@ -267,19 +224,17 @@ describe("aggregations-where-edge-bigint", () => { const someBigIntLT = `${bigInt}1`; - const neoSchema = new Neo4jGraphQL({ typeDefs }); - try { await session.run( ` - CREATE (:Post {testString: "${testString}"})<-[:LIKES {someBigInt: toInteger(${bigInt})}]-(:User {testString: "${testString}"}) - CREATE (:Post {testString: "${testString}"}) + CREATE (:${Post} {testString: "${testString}"})<-[:LIKES {someBigInt: toInteger(${bigInt})}]-(:${User} {testString: "${testString}"}) + CREATE (:${Post} {testString: "${testString}"}) ` ); const query = ` { - posts(where: { testString: "${testString}", likesAggregate: { edge: { someBigInt_LT: ${someBigIntLT} } } }) { + ${Post.plural}(where: { testString: "${testString}", likesAggregate: { edge: { someBigInt_LT: ${someBigIntLT} } } }) { testString likes { testString @@ -300,7 +255,7 @@ describe("aggregations-where-edge-bigint", () => { expect(gqlResult.errors).toBeUndefined(); - expect((gqlResult.data as any).posts).toEqual([ + expect((gqlResult.data as any)[Post.plural]).toEqual([ { testString, likes: [{ testString }], @@ -314,39 +269,22 @@ describe("aggregations-where-edge-bigint", () => { test("should return posts where a edge like BigInt is LTE than", async () => { const session = await neo4j.getSession(); - const typeDefs = ` - type User { - testString: String! - } - - type Post { - testString: String! - likes: [User!]! @relationship(type: "LIKES", direction: IN, properties: "Likes") - } - - type Likes @relationshipProperties { - someBigInt: BigInt - } - `; - const testString = generate({ charset: "alphabetic", readable: true, }); - const neoSchema = new Neo4jGraphQL({ typeDefs }); - try { await session.run( ` - CREATE (:Post {testString: "${testString}"})<-[:LIKES {someBigInt: toInteger(${bigInt})}]-(:User {testString: "${testString}"}) - CREATE (:Post {testString: "${testString}"}) + CREATE (:${Post} {testString: "${testString}"})<-[:LIKES {someBigInt: toInteger(${bigInt})}]-(:${User} {testString: "${testString}"}) + CREATE (:${Post} {testString: "${testString}"}) ` ); const query = ` { - posts(where: { testString: "${testString}", likesAggregate: { edge: { someBigInt_LTE: ${bigInt} } } }) { + ${Post.plural}(where: { testString: "${testString}", likesAggregate: { edge: { someBigInt_LTE: ${bigInt} } } }) { testString likes { testString @@ -367,7 +305,7 @@ describe("aggregations-where-edge-bigint", () => { expect(gqlResult.errors).toBeUndefined(); - expect((gqlResult.data as any).posts).toEqual([ + expect((gqlResult.data as any)[Post.plural]).toEqual([ { testString, likes: [{ testString }], diff --git a/packages/graphql/tests/integration/aggregations/where/edge/datetime.int.test.ts b/packages/graphql/tests/integration/aggregations/where/edge/datetime.int.test.ts index 9e973a67ea..0d3ca5372e 100644 --- a/packages/graphql/tests/integration/aggregations/where/edge/datetime.int.test.ts +++ b/packages/graphql/tests/integration/aggregations/where/edge/datetime.int.test.ts @@ -21,38 +21,45 @@ import { graphql } from "graphql"; import type { Driver } from "neo4j-driver"; import { generate } from "randomstring"; import { Neo4jGraphQL } from "../../../../../src/classes"; +import { UniqueType } from "../../../../utils/graphql-types"; import Neo4jHelper from "../../../neo4j"; describe("aggregations-where-edge-datetime", () => { let driver: Driver; let neo4j: Neo4jHelper; + let neoSchema: Neo4jGraphQL; + let User: UniqueType; + let Post: UniqueType; beforeAll(async () => { neo4j = new Neo4jHelper(); driver = await neo4j.getDriver(); - }); - - afterAll(async () => { - await driver.close(); - }); - - test("should return posts where a edge like DateTime is EQUAL to", async () => { - const session = await neo4j.getSession(); + User = new UniqueType("User"); + Post = new UniqueType("Post"); const typeDefs = ` - type User { + type ${User} { testString: String! } - - type Post { + + type ${Post} { testString: String! - likes: [User!]! @relationship(type: "LIKES", direction: IN, properties: "Likes") + likes: [${User}!]! @relationship(type: "LIKES", direction: IN, properties: "Likes") } - + type Likes @relationshipProperties { someDateTime: DateTime } `; + neoSchema = new Neo4jGraphQL({ typeDefs }); + }); + + afterAll(async () => { + await driver.close(); + }); + + test("should return posts where a edge like DateTime is EQUAL to", async () => { + const session = await neo4j.getSession(); const testString = generate({ charset: "alphabetic", @@ -61,19 +68,19 @@ describe("aggregations-where-edge-datetime", () => { const someDateTime = new Date(); - const neoSchema = new Neo4jGraphQL({ typeDefs }); - try { await session.run( ` - CREATE (:Post {testString: "${testString}"})<-[:LIKES {someDateTime: dateTime("${someDateTime.toISOString()}")}]-(:User {testString: "${testString}"}) - CREATE (:Post {testString: "${testString}"}) + CREATE (:${Post} {testString: "${testString}"})<-[:LIKES {someDateTime: dateTime("${someDateTime.toISOString()}")}]-(:${User} {testString: "${testString}"}) + CREATE (:${Post} {testString: "${testString}"}) ` ); const query = ` { - posts(where: { testString: "${testString}", likesAggregate: { edge: { someDateTime_EQUAL: "${someDateTime.toISOString()}" } } }) { + ${ + Post.plural + }(where: { testString: "${testString}", likesAggregate: { edge: { someDateTime_EQUAL: "${someDateTime.toISOString()}" } } }) { testString likes { testString @@ -94,7 +101,7 @@ describe("aggregations-where-edge-datetime", () => { expect(gqlResult.errors).toBeUndefined(); - expect((gqlResult.data as any).posts).toEqual([ + expect((gqlResult.data as any)[Post.plural]).toEqual([ { testString, likes: [{ testString }], @@ -108,21 +115,6 @@ describe("aggregations-where-edge-datetime", () => { test("should return posts where a edge like DateTime is GT than", async () => { const session = await neo4j.getSession(); - const typeDefs = ` - type User { - testString: String! - } - - type Post { - testString: String! - likes: [User!]! @relationship(type: "LIKES", direction: IN, properties: "Likes") - } - - type Likes @relationshipProperties { - someDateTime: DateTime - } - `; - const testString = generate({ charset: "alphabetic", readable: true, @@ -132,19 +124,19 @@ describe("aggregations-where-edge-datetime", () => { const someDateTimeGT = new Date(); someDateTimeGT.setDate(someDateTimeGT.getDate() - 1); - const neoSchema = new Neo4jGraphQL({ typeDefs }); - try { await session.run( ` - CREATE (:Post {testString: "${testString}"})<-[:LIKES {someDateTime: datetime("${someDateTime.toISOString()}")}]-(:User {testString: "${testString}"}) - CREATE (:Post {testString: "${testString}"}) + CREATE (:${Post} {testString: "${testString}"})<-[:LIKES {someDateTime: datetime("${someDateTime.toISOString()}")}]-(:${User} {testString: "${testString}"}) + CREATE (:${Post} {testString: "${testString}"}) ` ); const query = ` { - posts(where: { testString: "${testString}", likesAggregate: { edge: { someDateTime_GT: "${someDateTimeGT.toISOString()}" } } }) { + ${ + Post.plural + }(where: { testString: "${testString}", likesAggregate: { edge: { someDateTime_GT: "${someDateTimeGT.toISOString()}" } } }) { testString likes { testString @@ -165,7 +157,7 @@ describe("aggregations-where-edge-datetime", () => { expect(gqlResult.errors).toBeUndefined(); - expect((gqlResult.data as any).posts).toEqual([ + expect((gqlResult.data as any)[Post.plural]).toEqual([ { testString, likes: [{ testString }], @@ -179,21 +171,6 @@ describe("aggregations-where-edge-datetime", () => { test("should return posts where a edge like DateTime is GTE than", async () => { const session = await neo4j.getSession(); - const typeDefs = ` - type User { - testString: String! - } - - type Post { - testString: String! - likes: [User!]! @relationship(type: "LIKES", direction: IN, properties: "Likes") - } - - type Likes @relationshipProperties { - someDateTime: DateTime - } - `; - const testString = generate({ charset: "alphabetic", readable: true, @@ -201,19 +178,19 @@ describe("aggregations-where-edge-datetime", () => { const someDateTime = new Date(); - const neoSchema = new Neo4jGraphQL({ typeDefs }); - try { await session.run( ` - CREATE (:Post {testString: "${testString}"})<-[:LIKES {someDateTime: datetime("${someDateTime.toISOString()}")}]-(:User {testString: "${testString}"}) - CREATE (:Post {testString: "${testString}"}) + CREATE (:${Post} {testString: "${testString}"})<-[:LIKES {someDateTime: datetime("${someDateTime.toISOString()}")}]-(:${User} {testString: "${testString}"}) + CREATE (:${Post} {testString: "${testString}"}) ` ); const query = ` { - posts(where: { testString: "${testString}", likesAggregate: { edge: { someDateTime_GTE: "${someDateTime.toISOString()}" } } }) { + ${ + Post.plural + }(where: { testString: "${testString}", likesAggregate: { edge: { someDateTime_GTE: "${someDateTime.toISOString()}" } } }) { testString likes { testString @@ -234,7 +211,7 @@ describe("aggregations-where-edge-datetime", () => { expect(gqlResult.errors).toBeUndefined(); - expect((gqlResult.data as any).posts).toEqual([ + expect((gqlResult.data as any)[Post.plural]).toEqual([ { testString, likes: [{ testString }], @@ -248,21 +225,6 @@ describe("aggregations-where-edge-datetime", () => { test("should return posts where a edge like DateTime is LT than", async () => { const session = await neo4j.getSession(); - const typeDefs = ` - type User { - testString: String! - } - - type Post { - testString: String! - likes: [User!]! @relationship(type: "LIKES", direction: IN, properties: "Likes") - } - - type Likes @relationshipProperties { - someDateTime: DateTime - } - `; - const testString = generate({ charset: "alphabetic", readable: true, @@ -272,19 +234,19 @@ describe("aggregations-where-edge-datetime", () => { const someDateTimeLT = new Date(); someDateTimeLT.setDate(someDateTimeLT.getDate() + 1); - const neoSchema = new Neo4jGraphQL({ typeDefs }); - try { await session.run( ` - CREATE (:Post {testString: "${testString}"})<-[:LIKES {someDateTime: datetime("${someDateTime.toISOString()}")}]-(:User {testString: "${testString}"}) - CREATE (:Post {testString: "${testString}"}) + CREATE (:${Post} {testString: "${testString}"})<-[:LIKES {someDateTime: datetime("${someDateTime.toISOString()}")}]-(:${User} {testString: "${testString}"}) + CREATE (:${Post} {testString: "${testString}"}) ` ); const query = ` { - posts(where: { testString: "${testString}", likesAggregate: { edge: { someDateTime_LT: "${someDateTimeLT.toISOString()}" } } }) { + ${ + Post.plural + }(where: { testString: "${testString}", likesAggregate: { edge: { someDateTime_LT: "${someDateTimeLT.toISOString()}" } } }) { testString likes { testString @@ -305,7 +267,7 @@ describe("aggregations-where-edge-datetime", () => { expect(gqlResult.errors).toBeUndefined(); - expect((gqlResult.data as any).posts).toEqual([ + expect((gqlResult.data as any)[Post.plural]).toEqual([ { testString, likes: [{ testString }], @@ -319,21 +281,6 @@ describe("aggregations-where-edge-datetime", () => { test("should return posts where a edge like DateTime is LTE than", async () => { const session = await neo4j.getSession(); - const typeDefs = ` - type User { - testString: String! - } - - type Post { - testString: String! - likes: [User!]! @relationship(type: "LIKES", direction: IN, properties: "Likes") - } - - type Likes @relationshipProperties { - someDateTime: DateTime - } - `; - const testString = generate({ charset: "alphabetic", readable: true, @@ -341,19 +288,19 @@ describe("aggregations-where-edge-datetime", () => { const someDateTime = new Date(); - const neoSchema = new Neo4jGraphQL({ typeDefs }); - try { await session.run( ` - CREATE (:Post {testString: "${testString}"})<-[:LIKES {someDateTime: datetime("${someDateTime.toISOString()}")}]-(:User {testString: "${testString}"}) - CREATE (:Post {testString: "${testString}"}) + CREATE (:${Post} {testString: "${testString}"})<-[:LIKES {someDateTime: datetime("${someDateTime.toISOString()}")}]-(:${User} {testString: "${testString}"}) + CREATE (:${Post} {testString: "${testString}"}) ` ); const query = ` { - posts(where: { testString: "${testString}", likesAggregate: { edge: { someDateTime_LTE: "${someDateTime.toISOString()}" } } }) { + ${ + Post.plural + }(where: { testString: "${testString}", likesAggregate: { edge: { someDateTime_LTE: "${someDateTime.toISOString()}" } } }) { testString likes { testString @@ -374,7 +321,7 @@ describe("aggregations-where-edge-datetime", () => { expect(gqlResult.errors).toBeUndefined(); - expect((gqlResult.data as any).posts).toEqual([ + expect((gqlResult.data as any)[Post.plural]).toEqual([ { testString, likes: [{ testString }], diff --git a/packages/graphql/tests/integration/aggregations/where/edge/float.int.test.ts b/packages/graphql/tests/integration/aggregations/where/edge/float.int.test.ts index 1e71c75f6b..a4b4d1e3bd 100644 --- a/packages/graphql/tests/integration/aggregations/where/edge/float.int.test.ts +++ b/packages/graphql/tests/integration/aggregations/where/edge/float.int.test.ts @@ -21,32 +21,30 @@ import { graphql } from "graphql"; import type { Driver } from "neo4j-driver"; import { generate } from "randomstring"; import { Neo4jGraphQL } from "../../../../../src/classes"; +import { UniqueType } from "../../../../utils/graphql-types"; import Neo4jHelper from "../../../neo4j"; describe("aggregations-where-edge-float", () => { let driver: Driver; let neo4j: Neo4jHelper; + let neoSchema: Neo4jGraphQL; + let User: UniqueType; + let Post: UniqueType; beforeAll(async () => { neo4j = new Neo4jHelper(); driver = await neo4j.getDriver(); - }); - - afterAll(async () => { - await driver.close(); - }); - - test("should return posts where a edge like Float is EQUAL to", async () => { - const session = await neo4j.getSession(); + User = new UniqueType("User"); + Post = new UniqueType("Post"); const typeDefs = ` - type User { + type ${User} { testString: String! } - type Post { + type ${Post} { testString: String! - likes: [User!]! @relationship(type: "LIKES", direction: IN, properties: "Likes") + likes: [${User}!]! @relationship(type: "LIKES", direction: IN, properties: "Likes") } type Likes @relationshipProperties { @@ -54,6 +52,16 @@ describe("aggregations-where-edge-float", () => { } `; + neoSchema = new Neo4jGraphQL({ typeDefs }); + }); + + afterAll(async () => { + await driver.close(); + }); + + test("should return posts where a edge like Float is EQUAL to", async () => { + const session = await neo4j.getSession(); + const testString = generate({ charset: "alphabetic", readable: true, @@ -61,19 +69,17 @@ describe("aggregations-where-edge-float", () => { const someFloat = Math.random() * Math.random() + 10.123; - const neoSchema = new Neo4jGraphQL({ typeDefs }); - try { await session.run( ` - CREATE (:Post {testString: "${testString}"})<-[:LIKES {someFloat: ${someFloat}}]-(:User {testString: "${testString}"}) - CREATE (:Post {testString: "${testString}"}) + CREATE (:${Post} {testString: "${testString}"})<-[:LIKES {someFloat: ${someFloat}}]-(:${User} {testString: "${testString}"}) + CREATE (:${Post} {testString: "${testString}"}) ` ); const query = ` { - posts(where: { testString: "${testString}", likesAggregate: { edge: { someFloat_EQUAL: ${someFloat} } } }) { + ${Post.plural}(where: { testString: "${testString}", likesAggregate: { edge: { someFloat_EQUAL: ${someFloat} } } }) { testString likes { testString @@ -94,7 +100,7 @@ describe("aggregations-where-edge-float", () => { expect(gqlResult.errors).toBeUndefined(); - expect((gqlResult.data as any).posts).toEqual([ + expect((gqlResult.data as any)[Post.plural]).toEqual([ { testString, likes: [{ testString }], @@ -108,21 +114,6 @@ describe("aggregations-where-edge-float", () => { test("should return posts where a edge like Float is GT than", async () => { const session = await neo4j.getSession(); - const typeDefs = ` - type User { - testString: String! - } - - type Post { - testString: String! - likes: [User!]! @relationship(type: "LIKES", direction: IN, properties: "Likes") - } - - type Likes @relationshipProperties { - someFloat: Float - } - `; - const testString = generate({ charset: "alphabetic", readable: true, @@ -131,19 +122,17 @@ describe("aggregations-where-edge-float", () => { const someFloat = Math.random() * Math.random() + 10.123; const someFloatGt = someFloat - 0.1; - const neoSchema = new Neo4jGraphQL({ typeDefs }); - try { await session.run( ` - CREATE (:Post {testString: "${testString}"})<-[:LIKES {someFloat: ${someFloat}}]-(:User {testString: "${testString}"}) - CREATE (:Post {testString: "${testString}"}) + CREATE (:${Post} {testString: "${testString}"})<-[:LIKES {someFloat: ${someFloat}}]-(:${User} {testString: "${testString}"}) + CREATE (:${Post} {testString: "${testString}"}) ` ); const query = ` { - posts(where: { testString: "${testString}", likesAggregate: { edge: { someFloat_GT: ${someFloatGt} } } }) { + ${Post.plural}(where: { testString: "${testString}", likesAggregate: { edge: { someFloat_GT: ${someFloatGt} } } }) { testString likes { testString @@ -164,7 +153,7 @@ describe("aggregations-where-edge-float", () => { expect(gqlResult.errors).toBeUndefined(); - expect((gqlResult.data as any).posts).toEqual([ + expect((gqlResult.data as any)[Post.plural]).toEqual([ { testString, likes: [{ testString }], @@ -178,21 +167,6 @@ describe("aggregations-where-edge-float", () => { test("should return posts where a edge like Float is GTE than", async () => { const session = await neo4j.getSession(); - const typeDefs = ` - type User { - testString: String! - } - - type Post { - testString: String! - likes: [User!]! @relationship(type: "LIKES", direction: IN, properties: "Likes") - } - - type Likes @relationshipProperties { - someFloat: Float - } - `; - const testString = generate({ charset: "alphabetic", readable: true, @@ -200,19 +174,17 @@ describe("aggregations-where-edge-float", () => { const someFloat = Math.random() * Math.random() + 10.123; - const neoSchema = new Neo4jGraphQL({ typeDefs }); - try { await session.run( ` - CREATE (:Post {testString: "${testString}"})<-[:LIKES {someFloat: ${someFloat}}]-(:User {testString: "${testString}"}) - CREATE (:Post {testString: "${testString}"}) + CREATE (:${Post} {testString: "${testString}"})<-[:LIKES {someFloat: ${someFloat}}]-(:${User} {testString: "${testString}"}) + CREATE (:${Post} {testString: "${testString}"}) ` ); const query = ` { - posts(where: { testString: "${testString}", likesAggregate: { edge: { someFloat_GTE: ${someFloat} } } }) { + ${Post.plural}(where: { testString: "${testString}", likesAggregate: { edge: { someFloat_GTE: ${someFloat} } } }) { testString likes { testString @@ -233,7 +205,7 @@ describe("aggregations-where-edge-float", () => { expect(gqlResult.errors).toBeUndefined(); - expect((gqlResult.data as any).posts).toEqual([ + expect((gqlResult.data as any)[Post.plural]).toEqual([ { testString, likes: [{ testString }], @@ -247,21 +219,6 @@ describe("aggregations-where-edge-float", () => { test("should return posts where a edge like Float is LT than", async () => { const session = await neo4j.getSession(); - const typeDefs = ` - type User { - testString: String! - } - - type Post { - testString: String! - likes: [User!]! @relationship(type: "LIKES", direction: IN, properties: "Likes") - } - - type Likes @relationshipProperties { - someFloat: Float - } - `; - const testString = generate({ charset: "alphabetic", readable: true, @@ -270,19 +227,17 @@ describe("aggregations-where-edge-float", () => { const someFloat = Math.random() * Math.random() + 10.123; const someFloatLT = someFloat + 0.1; - const neoSchema = new Neo4jGraphQL({ typeDefs }); - try { await session.run( ` - CREATE (:Post {testString: "${testString}"})<-[:LIKES {someFloat: ${someFloat}}]-(:User {testString: "${testString}"}) - CREATE (:Post {testString: "${testString}"}) + CREATE (:${Post} {testString: "${testString}"})<-[:LIKES {someFloat: ${someFloat}}]-(:${User} {testString: "${testString}"}) + CREATE (:${Post} {testString: "${testString}"}) ` ); const query = ` { - posts(where: { testString: "${testString}", likesAggregate: { edge: { someFloat_LT: ${someFloatLT} } } }) { + ${Post.plural}(where: { testString: "${testString}", likesAggregate: { edge: { someFloat_LT: ${someFloatLT} } } }) { testString likes { testString @@ -303,7 +258,7 @@ describe("aggregations-where-edge-float", () => { expect(gqlResult.errors).toBeUndefined(); - expect((gqlResult.data as any).posts).toEqual([ + expect((gqlResult.data as any)[Post.plural]).toEqual([ { testString, likes: [{ testString }], @@ -317,21 +272,6 @@ describe("aggregations-where-edge-float", () => { test("should return posts where a edge like Float is LTE than", async () => { const session = await neo4j.getSession(); - const typeDefs = ` - type User { - testString: String! - } - - type Post { - testString: String! - likes: [User!]! @relationship(type: "LIKES", direction: IN, properties: "Likes") - } - - type Likes @relationshipProperties { - someFloat: Float - } - `; - const testString = generate({ charset: "alphabetic", readable: true, @@ -339,19 +279,17 @@ describe("aggregations-where-edge-float", () => { const someFloat = Math.random() * Math.random() + 10.123; - const neoSchema = new Neo4jGraphQL({ typeDefs }); - try { await session.run( ` - CREATE (:Post {testString: "${testString}"})<-[:LIKES {someFloat: ${someFloat}}]-(:User {testString: "${testString}"}) - CREATE (:Post {testString: "${testString}"}) + CREATE (:${Post} {testString: "${testString}"})<-[:LIKES {someFloat: ${someFloat}}]-(:${User} {testString: "${testString}"}) + CREATE (:${Post} {testString: "${testString}"}) ` ); const query = ` { - posts(where: { testString: "${testString}", likesAggregate: { edge: { someFloat_LTE: ${someFloat} } } }) { + ${Post.plural}(where: { testString: "${testString}", likesAggregate: { edge: { someFloat_LTE: ${someFloat} } } }) { testString likes { testString @@ -372,7 +310,7 @@ describe("aggregations-where-edge-float", () => { expect(gqlResult.errors).toBeUndefined(); - expect((gqlResult.data as any).posts).toEqual([ + expect((gqlResult.data as any)[Post.plural]).toEqual([ { testString, likes: [{ testString }], diff --git a/packages/graphql/tests/integration/aggregations/where/edge/id.int.test.ts b/packages/graphql/tests/integration/aggregations/where/edge/id.int.test.ts index 8098a98da9..a670dbf38b 100644 --- a/packages/graphql/tests/integration/aggregations/where/edge/id.int.test.ts +++ b/packages/graphql/tests/integration/aggregations/where/edge/id.int.test.ts @@ -21,32 +21,30 @@ import { graphql } from "graphql"; import type { Driver } from "neo4j-driver"; import { generate } from "randomstring"; import { Neo4jGraphQL } from "../../../../../src/classes"; +import { UniqueType } from "../../../../utils/graphql-types"; import Neo4jHelper from "../../../neo4j"; describe("aggregations-where-edge-id", () => { let driver: Driver; let neo4j: Neo4jHelper; + let neoSchema: Neo4jGraphQL; + let Post: UniqueType; + let User: UniqueType; beforeAll(async () => { neo4j = new Neo4jHelper(); driver = await neo4j.getDriver(); - }); - - afterAll(async () => { - await driver.close(); - }); - - test("should return posts where a edge like ID is EQUAL to", async () => { - const session = await neo4j.getSession(); + Post = new UniqueType("Post"); + User = new UniqueType("User"); const typeDefs = ` - type User { + type ${User} { testString: String! } - type Post { + type ${Post} { testString: String! - likes: [User!]! @relationship(type: "LIKES", direction: IN, properties: "Likes") + likes: [${User}!]! @relationship(type: "LIKES", direction: IN, properties: "Likes") } type Likes @relationshipProperties { @@ -54,6 +52,16 @@ describe("aggregations-where-edge-id", () => { } `; + neoSchema = new Neo4jGraphQL({ typeDefs }); + }); + + afterAll(async () => { + await driver.close(); + }); + + test("should return posts where a edge like ID is EQUAL to", async () => { + const session = await neo4j.getSession(); + const testString = generate({ charset: "alphabetic", readable: true, @@ -64,19 +72,17 @@ describe("aggregations-where-edge-id", () => { readable: true, }); - const neoSchema = new Neo4jGraphQL({ typeDefs }); - try { await session.run( ` - CREATE (:Post {testString: "${testString}"})<-[:LIKES { testId: "${testId}" }]-(:User {testString: "${testString}"}) - CREATE (:Post {testString: "${testString}"}) + CREATE (:${Post} {testString: "${testString}"})<-[:LIKES { testId: "${testId}" }]-(:${User} {testString: "${testString}"}) + CREATE (:${Post} {testString: "${testString}"}) ` ); const query = ` { - posts(where: { testString: "${testString}", likesAggregate: { edge: { testId_EQUAL: "${testId}" } } }) { + ${Post.plural}(where: { testString: "${testString}", likesAggregate: { edge: { testId_EQUAL: "${testId}" } } }) { testString likes { testString @@ -97,7 +103,7 @@ describe("aggregations-where-edge-id", () => { expect(gqlResult.errors).toBeUndefined(); - expect((gqlResult.data as any).posts).toEqual([ + expect((gqlResult.data as any)[Post.plural]).toEqual([ { testString, likes: [{ testString }], diff --git a/packages/graphql/tests/integration/aggregations/where/edge/int.int.test.ts b/packages/graphql/tests/integration/aggregations/where/edge/int.int.test.ts index 958cf81f57..253b91dd7d 100644 --- a/packages/graphql/tests/integration/aggregations/where/edge/int.int.test.ts +++ b/packages/graphql/tests/integration/aggregations/where/edge/int.int.test.ts @@ -22,38 +22,45 @@ import { graphql } from "graphql"; import type { Driver } from "neo4j-driver"; import { generate } from "randomstring"; import { Neo4jGraphQL } from "../../../../../src/classes"; +import { UniqueType } from "../../../../utils/graphql-types"; import Neo4jHelper from "../../../neo4j"; describe("aggregations-where-edge-int", () => { let driver: Driver; let neo4j: Neo4jHelper; + let User: UniqueType; + let Post: UniqueType; + let neoSchema: Neo4jGraphQL; beforeAll(async () => { neo4j = new Neo4jHelper(); driver = await neo4j.getDriver(); - }); - - afterAll(async () => { - await driver.close(); - }); - - test("should return posts where a edge like Int is EQUAL to", async () => { - const session = await neo4j.getSession(); + User = new UniqueType("User"); + Post = new UniqueType("Post"); const typeDefs = ` - type User { + type ${User} { testString: String! } - - type Post { + + type ${Post} { testString: String! - likes: [User!]! @relationship(type: "LIKES", direction: IN, properties: "Likes") + likes: [${User}!]! @relationship(type: "LIKES", direction: IN, properties: "Likes") } - + type Likes @relationshipProperties { someInt: Int } `; + neoSchema = new Neo4jGraphQL({ typeDefs }); + }); + + afterAll(async () => { + await driver.close(); + }); + + test("should return posts where a edge like Int is EQUAL to", async () => { + const session = await neo4j.getSession(); const testString = generate({ charset: "alphabetic", @@ -62,19 +69,17 @@ describe("aggregations-where-edge-int", () => { const someInt = Number(faker.number.int({ max: 100000 })); - const neoSchema = new Neo4jGraphQL({ typeDefs }); - try { await session.run( ` - CREATE (:Post {testString: "${testString}"})<-[:LIKES { someInt: ${someInt} }]-(:User {testString: "${testString}"}) - CREATE (:Post {testString: "${testString}"}) + CREATE (:${Post} {testString: "${testString}"})<-[:LIKES { someInt: ${someInt} }]-(:${User} {testString: "${testString}"}) + CREATE (:${Post} {testString: "${testString}"}) ` ); const query = ` { - posts(where: { testString: "${testString}", likesAggregate: { edge: { someInt_EQUAL: ${someInt} } } }) { + ${Post.plural}(where: { testString: "${testString}", likesAggregate: { edge: { someInt_EQUAL: ${someInt} } } }) { testString likes { testString @@ -91,7 +96,7 @@ describe("aggregations-where-edge-int", () => { expect(gqlResult.errors).toBeUndefined(); - expect((gqlResult.data as any).posts).toEqual([ + expect((gqlResult.data as any)[Post.plural]).toEqual([ { testString, likes: [{ testString }], @@ -105,21 +110,6 @@ describe("aggregations-where-edge-int", () => { test("should return posts where a edge like Float is GT than", async () => { const session = await neo4j.getSession(); - const typeDefs = ` - type User { - testString: String! - } - - type Post { - testString: String! - likes: [User!]! @relationship(type: "LIKES", direction: IN, properties: "Likes") - } - - type Likes @relationshipProperties { - someInt: Int - } - `; - const testString = generate({ charset: "alphabetic", readable: true, @@ -128,19 +118,17 @@ describe("aggregations-where-edge-int", () => { const someInt = Number(faker.number.int({ max: 100000 })); const someIntGt = someInt - 1; - const neoSchema = new Neo4jGraphQL({ typeDefs }); - try { await session.run( ` - CREATE (:Post {testString: "${testString}"})<-[:LIKES { someInt: ${someInt} }]-(:User {testString: "${testString}"}) - CREATE (:Post {testString: "${testString}"}) + CREATE (:${Post} {testString: "${testString}"})<-[:LIKES { someInt: ${someInt} }]-(:${User} {testString: "${testString}"}) + CREATE (:${Post} {testString: "${testString}"}) ` ); const query = ` { - posts(where: { testString: "${testString}", likesAggregate: { edge: { someInt_GT: ${someIntGt} } } }) { + ${Post.plural}(where: { testString: "${testString}", likesAggregate: { edge: { someInt_GT: ${someIntGt} } } }) { testString likes { testString @@ -157,7 +145,7 @@ describe("aggregations-where-edge-int", () => { expect(gqlResult.errors).toBeUndefined(); - expect((gqlResult.data as any).posts).toEqual([ + expect((gqlResult.data as any)[Post.plural]).toEqual([ { testString, likes: [{ testString }], @@ -171,22 +159,6 @@ describe("aggregations-where-edge-int", () => { test("should return posts where a edge like Float is GTE than", async () => { const session = await neo4j.getSession(); - const typeDefs = ` - type User { - testString: String! - someInt: Int! - } - - type Post { - testString: String! - likes: [User!]! @relationship(type: "LIKES", direction: IN, properties: "Likes") - } - - type Likes @relationshipProperties { - someInt: Int - } - `; - const testString = generate({ charset: "alphabetic", readable: true, @@ -194,19 +166,17 @@ describe("aggregations-where-edge-int", () => { const someInt = Number(faker.number.int({ max: 100000 })); - const neoSchema = new Neo4jGraphQL({ typeDefs }); - try { await session.run( ` - CREATE (:Post {testString: "${testString}"})<-[:LIKES { someInt: ${someInt} }]-(:User {testString: "${testString}"}) - CREATE (:Post {testString: "${testString}"}) + CREATE (:${Post} {testString: "${testString}"})<-[:LIKES { someInt: ${someInt} }]-(:${User} {testString: "${testString}"}) + CREATE (:${Post} {testString: "${testString}"}) ` ); const query = ` { - posts(where: { testString: "${testString}", likesAggregate: { edge: { someInt_GTE: ${someInt} } } }) { + ${Post.plural}(where: { testString: "${testString}", likesAggregate: { edge: { someInt_GTE: ${someInt} } } }) { testString likes { testString @@ -223,7 +193,7 @@ describe("aggregations-where-edge-int", () => { expect(gqlResult.errors).toBeUndefined(); - expect((gqlResult.data as any).posts).toEqual([ + expect((gqlResult.data as any)[Post.plural]).toEqual([ { testString, likes: [{ testString }], @@ -237,22 +207,6 @@ describe("aggregations-where-edge-int", () => { test("should return posts where a edge like Float is LT than", async () => { const session = await neo4j.getSession(); - const typeDefs = ` - type User { - testString: String! - someInt: Int! - } - - type Post { - testString: String! - likes: [User!]! @relationship(type: "LIKES", direction: IN, properties: "Likes") - } - - type Likes @relationshipProperties { - someInt: Int - } - `; - const testString = generate({ charset: "alphabetic", readable: true, @@ -261,19 +215,17 @@ describe("aggregations-where-edge-int", () => { const someInt = Number(faker.number.int({ max: 100000 })); const someIntLT = someInt + 1; - const neoSchema = new Neo4jGraphQL({ typeDefs }); - try { await session.run( ` - CREATE (:Post {testString: "${testString}"})<-[:LIKES { someInt: ${someInt} }]-(:User {testString: "${testString}"}) - CREATE (:Post {testString: "${testString}"}) + CREATE (:${Post} {testString: "${testString}"})<-[:LIKES { someInt: ${someInt} }]-(:${User} {testString: "${testString}"}) + CREATE (:${Post} {testString: "${testString}"}) ` ); const query = ` { - posts(where: { testString: "${testString}", likesAggregate: { edge: { someInt_LT: ${someIntLT} } } }) { + ${Post.plural}(where: { testString: "${testString}", likesAggregate: { edge: { someInt_LT: ${someIntLT} } } }) { testString likes { testString @@ -290,7 +242,7 @@ describe("aggregations-where-edge-int", () => { expect(gqlResult.errors).toBeUndefined(); - expect((gqlResult.data as any).posts).toEqual([ + expect((gqlResult.data as any)[Post.plural]).toEqual([ { testString, likes: [{ testString }], @@ -304,21 +256,6 @@ describe("aggregations-where-edge-int", () => { test("should return posts where a edge like Float is LTE than", async () => { const session = await neo4j.getSession(); - const typeDefs = ` - type User { - testString: String! - } - - type Post { - testString: String! - likes: [User!]! @relationship(type: "LIKES", direction: IN, properties: "Likes") - } - - type Likes @relationshipProperties { - someInt: Int - } - `; - const testString = generate({ charset: "alphabetic", readable: true, @@ -326,19 +263,17 @@ describe("aggregations-where-edge-int", () => { const someInt = Number(faker.number.int({ max: 100000 })); - const neoSchema = new Neo4jGraphQL({ typeDefs }); - try { await session.run( ` - CREATE (:Post {testString: "${testString}"})<-[:LIKES { someInt: ${someInt} }]-(:User {testString: "${testString}"}) - CREATE (:Post {testString: "${testString}"}) + CREATE (:${Post} {testString: "${testString}"})<-[:LIKES { someInt: ${someInt} }]-(:${User} {testString: "${testString}"}) + CREATE (:${Post} {testString: "${testString}"}) ` ); const query = ` { - posts(where: { testString: "${testString}", likesAggregate: { edge: { someInt_LTE: ${someInt} } } }) { + ${Post.plural}(where: { testString: "${testString}", likesAggregate: { edge: { someInt_LTE: ${someInt} } } }) { testString likes { testString @@ -355,7 +290,7 @@ describe("aggregations-where-edge-int", () => { expect(gqlResult.errors).toBeUndefined(); - expect((gqlResult.data as any).posts).toEqual([ + expect((gqlResult.data as any)[Post.plural]).toEqual([ { testString, likes: [{ testString }], @@ -367,21 +302,6 @@ describe("aggregations-where-edge-int", () => { }); describe("AVERAGE", () => { - const typeDefs = ` - type User { - testString: String! - } - - type Post { - testString: String! - likes: [User!]! @relationship(type: "LIKES", direction: IN, properties: "Likes") - } - - type Likes @relationshipProperties { - someInt: Int - } - `; - const someInt1 = 1; const someInt2 = 2; const someInt3 = 3; @@ -396,22 +316,20 @@ describe("aggregations-where-edge-int", () => { const avg = (someInt1 + someInt2 + someInt3) / 3; - const neoSchema = new Neo4jGraphQL({ typeDefs }); - try { await session.run( ` - CREATE (p:Post {testString: "${testString}"}) - CREATE (p)<-[:LIKES { someInt: ${someInt1} }]-(:User {testString: "${testString}"}) - CREATE (p)<-[:LIKES { someInt: ${someInt2} }]-(:User {testString: "${testString}"}) - CREATE (p)<-[:LIKES { someInt: ${someInt3} }]-(:User {testString: "${testString}"}) - CREATE (:Post {testString: "${testString}"}) + CREATE (p:${Post} {testString: "${testString}"}) + CREATE (p)<-[:LIKES { someInt: ${someInt1} }]-(:${User} {testString: "${testString}"}) + CREATE (p)<-[:LIKES { someInt: ${someInt2} }]-(:${User} {testString: "${testString}"}) + CREATE (p)<-[:LIKES { someInt: ${someInt3} }]-(:${User} {testString: "${testString}"}) + CREATE (:${Post} {testString: "${testString}"}) ` ); const query = ` { - posts(where: { testString: "${testString}", likesAggregate: { edge: { someInt_AVERAGE_EQUAL: ${avg} } } }) { + ${Post.plural}(where: { testString: "${testString}", likesAggregate: { edge: { someInt_AVERAGE_EQUAL: ${avg} } } }) { testString likes { testString @@ -428,7 +346,7 @@ describe("aggregations-where-edge-int", () => { expect(gqlResult.errors).toBeUndefined(); - const [post] = (gqlResult.data as any).posts as any[]; + const [post] = (gqlResult.data as any)[Post.plural] as any[]; expect(post.testString).toEqual(testString); expect(post.likes).toHaveLength(3); } finally { @@ -447,22 +365,20 @@ describe("aggregations-where-edge-int", () => { const avg = (someInt1 + someInt2 + someInt3) / 3; const avgGT = avg - 1; - const neoSchema = new Neo4jGraphQL({ typeDefs }); - try { await session.run( ` - CREATE (p:Post {testString: "${testString}"}) - CREATE (p)<-[:LIKES { someInt: ${someInt1} }]-(:User {testString: "${testString}"}) - CREATE (p)<-[:LIKES { someInt: ${someInt2} }]-(:User {testString: "${testString}"}) - CREATE (p)<-[:LIKES { someInt: ${someInt3} }]-(:User {testString: "${testString}"}) - CREATE (:Post {testString: "${testString}"}) + CREATE (p:${Post} {testString: "${testString}"}) + CREATE (p)<-[:LIKES { someInt: ${someInt1} }]-(:${User} {testString: "${testString}"}) + CREATE (p)<-[:LIKES { someInt: ${someInt2} }]-(:${User} {testString: "${testString}"}) + CREATE (p)<-[:LIKES { someInt: ${someInt3} }]-(:${User} {testString: "${testString}"}) + CREATE (:${Post} {testString: "${testString}"}) ` ); const query = ` { - posts(where: { testString: "${testString}", likesAggregate: { edge: { someInt_AVERAGE_GT: ${avgGT} } } }) { + ${Post.plural}(where: { testString: "${testString}", likesAggregate: { edge: { someInt_AVERAGE_GT: ${avgGT} } } }) { testString likes { testString @@ -479,7 +395,7 @@ describe("aggregations-where-edge-int", () => { expect(gqlResult.errors).toBeUndefined(); - const [post] = (gqlResult.data as any).posts as any[]; + const [post] = (gqlResult.data as any)[Post.plural] as any[]; expect(post.testString).toEqual(testString); expect(post.likes).toHaveLength(3); } finally { @@ -497,22 +413,20 @@ describe("aggregations-where-edge-int", () => { const avg = (someInt1 + someInt2 + someInt3) / 3; - const neoSchema = new Neo4jGraphQL({ typeDefs }); - try { await session.run( ` - CREATE (p:Post {testString: "${testString}"}) - CREATE (p)<-[:LIKES { someInt: ${someInt1} }]-(:User {testString: "${testString}"}) - CREATE (p)<-[:LIKES { someInt: ${someInt2} }]-(:User {testString: "${testString}"}) - CREATE (p)<-[:LIKES { someInt: ${someInt3} }]-(:User {testString: "${testString}"}) - CREATE (:Post {testString: "${testString}"}) + CREATE (p:${Post} {testString: "${testString}"}) + CREATE (p)<-[:LIKES { someInt: ${someInt1} }]-(:${User} {testString: "${testString}"}) + CREATE (p)<-[:LIKES { someInt: ${someInt2} }]-(:${User} {testString: "${testString}"}) + CREATE (p)<-[:LIKES { someInt: ${someInt3} }]-(:${User} {testString: "${testString}"}) + CREATE (:${Post} {testString: "${testString}"}) ` ); const query = ` { - posts(where: { testString: "${testString}", likesAggregate: { edge: { someInt_AVERAGE_GTE: ${avg} } } }) { + ${Post.plural}(where: { testString: "${testString}", likesAggregate: { edge: { someInt_AVERAGE_GTE: ${avg} } } }) { testString likes { testString @@ -528,7 +442,7 @@ describe("aggregations-where-edge-int", () => { }); expect(gqlResult.errors).toBeUndefined(); - const [post] = (gqlResult.data as any).posts as any[]; + const [post] = (gqlResult.data as any)[Post.plural] as any[]; expect(post.testString).toEqual(testString); expect(post.likes).toHaveLength(3); } finally { @@ -547,22 +461,20 @@ describe("aggregations-where-edge-int", () => { const avg = (someInt1 + someInt2 + someInt3) / 3; const avgLT = avg + 1; - const neoSchema = new Neo4jGraphQL({ typeDefs }); - try { await session.run( ` - CREATE (p:Post {testString: "${testString}"}) - CREATE (p)<-[:LIKES { someInt: ${someInt1} }]-(:User {testString: "${testString}"}) - CREATE (p)<-[:LIKES { someInt: ${someInt2} }]-(:User {testString: "${testString}"}) - CREATE (p)<-[:LIKES { someInt: ${someInt3} }]-(:User {testString: "${testString}"}) - CREATE (:Post {testString: "${testString}"}) + CREATE (p:${Post} {testString: "${testString}"}) + CREATE (p)<-[:LIKES { someInt: ${someInt1} }]-(:${User} {testString: "${testString}"}) + CREATE (p)<-[:LIKES { someInt: ${someInt2} }]-(:${User} {testString: "${testString}"}) + CREATE (p)<-[:LIKES { someInt: ${someInt3} }]-(:${User} {testString: "${testString}"}) + CREATE (:${Post} {testString: "${testString}"}) ` ); const query = ` { - posts(where: { testString: "${testString}", likesAggregate: { edge: { someInt_AVERAGE_LT: ${avgLT} } } }) { + ${Post.plural}(where: { testString: "${testString}", likesAggregate: { edge: { someInt_AVERAGE_LT: ${avgLT} } } }) { testString likes { testString @@ -579,7 +491,7 @@ describe("aggregations-where-edge-int", () => { expect(gqlResult.errors).toBeUndefined(); - const [post] = (gqlResult.data as any).posts as any[]; + const [post] = (gqlResult.data as any)[Post.plural] as any[]; expect(post.testString).toEqual(testString); expect(post.likes).toHaveLength(3); } finally { @@ -597,22 +509,20 @@ describe("aggregations-where-edge-int", () => { const avg = someInt1 + someInt2 + someInt3; - const neoSchema = new Neo4jGraphQL({ typeDefs }); - try { await session.run( ` - CREATE (p:Post {testString: "${testString}"}) - CREATE (p)<-[:LIKES { someInt: ${someInt1} }]-(:User {testString: "${testString}"}) - CREATE (p)<-[:LIKES { someInt: ${someInt2} }]-(:User {testString: "${testString}"}) - CREATE (p)<-[:LIKES { someInt: ${someInt3} }]-(:User {testString: "${testString}"}) - CREATE (:Post {testString: "${testString}"}) + CREATE (p:${Post} {testString: "${testString}"}) + CREATE (p)<-[:LIKES { someInt: ${someInt1} }]-(:${User} {testString: "${testString}"}) + CREATE (p)<-[:LIKES { someInt: ${someInt2} }]-(:${User} {testString: "${testString}"}) + CREATE (p)<-[:LIKES { someInt: ${someInt3} }]-(:${User} {testString: "${testString}"}) + CREATE (:${Post} {testString: "${testString}"}) ` ); const query = ` { - posts(where: { testString: "${testString}", likesAggregate: { edge: { someInt_AVERAGE_LTE: ${avg} } } }) { + ${Post.plural}(where: { testString: "${testString}", likesAggregate: { edge: { someInt_AVERAGE_LTE: ${avg} } } }) { testString likes { testString @@ -629,7 +539,7 @@ describe("aggregations-where-edge-int", () => { expect(gqlResult.errors).toBeUndefined(); - const [post] = (gqlResult.data as any).posts as any[]; + const [post] = (gqlResult.data as any)[Post.plural] as any[]; expect(post.testString).toEqual(testString); expect(post.likes).toHaveLength(3); } finally { @@ -642,21 +552,6 @@ describe("aggregations-where-edge-int", () => { test("should return posts where the sum of a edge like Int's is EQUAL to", async () => { const session = await neo4j.getSession(); - const typeDefs = ` - type User { - testString: String! - } - - type Post { - testString: String! - likes: [User!]! @relationship(type: "LIKES", direction: IN, properties: "Likes") - } - - type Likes @relationshipProperties { - someInt: Int - } - `; - const testString = generate({ charset: "alphabetic", readable: true, @@ -668,22 +563,20 @@ describe("aggregations-where-edge-int", () => { const sum = someInt1 + someInt2 + someInt3; - const neoSchema = new Neo4jGraphQL({ typeDefs }); - try { await session.run( ` - CREATE (p:Post {testString: "${testString}"}) - CREATE (p)<-[:LIKES { someInt: ${someInt1} }]-(:User {testString: "${testString}"}) - CREATE (p)<-[:LIKES { someInt: ${someInt2} }]-(:User {testString: "${testString}"}) - CREATE (p)<-[:LIKES { someInt: ${someInt3} }]-(:User {testString: "${testString}"}) - CREATE (:Post {testString: "${testString}"}) + CREATE (p:${Post} {testString: "${testString}"}) + CREATE (p)<-[:LIKES { someInt: ${someInt1} }]-(:${User} {testString: "${testString}"}) + CREATE (p)<-[:LIKES { someInt: ${someInt2} }]-(:${User} {testString: "${testString}"}) + CREATE (p)<-[:LIKES { someInt: ${someInt3} }]-(:${User} {testString: "${testString}"}) + CREATE (:${Post} {testString: "${testString}"}) ` ); const query = ` { - posts(where: { testString: "${testString}", likesAggregate: { edge: { someInt_SUM_EQUAL: ${sum} } } }) { + ${Post.plural}(where: { testString: "${testString}", likesAggregate: { edge: { someInt_SUM_EQUAL: ${sum} } } }) { testString likes { testString @@ -700,7 +593,7 @@ describe("aggregations-where-edge-int", () => { expect(gqlResult.errors).toBeUndefined(); - const [post] = (gqlResult.data as any).posts as any[]; + const [post] = (gqlResult.data as any)[Post.plural] as any[]; expect(post.testString).toEqual(testString); expect(post.likes).toHaveLength(3); } finally { diff --git a/packages/graphql/tests/integration/aggregations/where/node/bigint.int.test.ts b/packages/graphql/tests/integration/aggregations/where/node/bigint.int.test.ts index 864581922f..38805964a8 100644 --- a/packages/graphql/tests/integration/aggregations/where/node/bigint.int.test.ts +++ b/packages/graphql/tests/integration/aggregations/where/node/bigint.int.test.ts @@ -17,60 +17,65 @@ * limitations under the License. */ -import type { Driver } from "neo4j-driver"; import { graphql } from "graphql"; +import type { Driver } from "neo4j-driver"; import { generate } from "randomstring"; -import Neo4jHelper from "../../../neo4j"; import { Neo4jGraphQL } from "../../../../../src/classes"; +import { UniqueType } from "../../../../utils/graphql-types"; +import Neo4jHelper from "../../../neo4j"; describe("aggregations-where-node-bigint", () => { let driver: Driver; let neo4j: Neo4jHelper; - - const bigInt = "2147483647"; + let bigInt: string; + let User: UniqueType; + let Post: UniqueType; + let neoSchema: Neo4jGraphQL; beforeAll(async () => { neo4j = new Neo4jHelper(); driver = await neo4j.getDriver(); - }); - - afterAll(async () => { - await driver.close(); - }); - - test("should return posts where a like BigInt is EQUAL to", async () => { - const session = await neo4j.getSession(); + bigInt = "2147483647"; + User = new UniqueType("User"); + Post = new UniqueType("Post"); const typeDefs = ` - type User { + type ${User} { testString: String! someBigInt: BigInt } - - type Post { + + type ${Post} { testString: String! - likes: [User!]! @relationship(type: "LIKES", direction: IN) + likes: [${User}!]! @relationship(type: "LIKES", direction: IN) } `; + neoSchema = new Neo4jGraphQL({ typeDefs }); + }); + + afterAll(async () => { + await driver.close(); + }); + + test("should return posts where a like BigInt is EQUAL to", async () => { + const session = await neo4j.getSession(); const testString = generate({ charset: "alphabetic", readable: true, }); - const neoSchema = new Neo4jGraphQL({ typeDefs }); - try { await session.run( ` - CREATE (:Post {testString: "${testString}"})<-[:LIKES]-(:User {testString: "${testString}", someBigInt: toInteger(${bigInt})}) - CREATE (:Post {testString: "${testString}"}) + CREATE (:${Post} {testString: "${testString}"})<-[:LIKES]-(:${User} {testString: "${testString}", someBigInt: toInteger(${bigInt})}) + CREATE (:${Post} {testString: "${testString}"}) ` ); const query = ` { - posts(where: { testString: "${testString}", likesAggregate: { node: { someBigInt_EQUAL: ${bigInt} } } }) { + ${Post.plural}(where: { testString: "${testString}", likesAggregate: { node: { someBigInt_EQUAL: ${bigInt} } } }) { testString likes { testString @@ -92,7 +97,7 @@ describe("aggregations-where-node-bigint", () => { expect(gqlResult.errors).toBeUndefined(); - expect((gqlResult.data as any).posts).toEqual([ + expect((gqlResult.data as any)[Post.plural]).toEqual([ { testString, likes: [{ testString, someBigInt: bigInt }], @@ -106,18 +111,6 @@ describe("aggregations-where-node-bigint", () => { test("should return posts where a like BigInt is GT than", async () => { const session = await neo4j.getSession(); - const typeDefs = ` - type User { - testString: String! - someBigInt: BigInt - } - - type Post { - testString: String! - likes: [User!]! @relationship(type: "LIKES", direction: IN) - } - `; - const testString = generate({ charset: "alphabetic", readable: true, @@ -126,19 +119,17 @@ describe("aggregations-where-node-bigint", () => { const someBigInt = `${bigInt}1`; const someBigIntGt = bigInt.substring(0, bigInt.length - 1); - const neoSchema = new Neo4jGraphQL({ typeDefs }); - try { await session.run( ` - CREATE (:Post {testString: "${testString}"})<-[:LIKES]-(:User {testString: "${testString}", someBigInt: ${someBigInt}}) - CREATE (:Post {testString: "${testString}"}) + CREATE (:${Post} {testString: "${testString}"})<-[:LIKES]-(:${User} {testString: "${testString}", someBigInt: ${someBigInt}}) + CREATE (:${Post} {testString: "${testString}"}) ` ); const query = ` { - posts(where: { testString: "${testString}", likesAggregate: { node: { someBigInt_GT: ${someBigIntGt} } } }) { + ${Post.plural}(where: { testString: "${testString}", likesAggregate: { node: { someBigInt_GT: ${someBigIntGt} } } }) { testString likes { testString @@ -160,7 +151,7 @@ describe("aggregations-where-node-bigint", () => { expect(gqlResult.errors).toBeUndefined(); - expect((gqlResult.data as any).posts).toEqual([ + expect((gqlResult.data as any)[Post.plural]).toEqual([ { testString, likes: [{ testString, someBigInt }], @@ -174,36 +165,22 @@ describe("aggregations-where-node-bigint", () => { test("should return posts where a like BigInt is GTE than", async () => { const session = await neo4j.getSession(); - const typeDefs = ` - type User { - testString: String! - someBigInt: BigInt - } - - type Post { - testString: String! - likes: [User!]! @relationship(type: "LIKES", direction: IN) - } - `; - const testString = generate({ charset: "alphabetic", readable: true, }); - const neoSchema = new Neo4jGraphQL({ typeDefs }); - try { await session.run( ` - CREATE (:Post {testString: "${testString}"})<-[:LIKES]-(:User {testString: "${testString}", someBigInt: toInteger(${bigInt})}) - CREATE (:Post {testString: "${testString}"}) + CREATE (:${Post} {testString: "${testString}"})<-[:LIKES]-(:${User} {testString: "${testString}", someBigInt: toInteger(${bigInt})}) + CREATE (:${Post} {testString: "${testString}"}) ` ); const query = ` { - posts(where: { testString: "${testString}", likesAggregate: { node: { someBigInt_GTE: ${bigInt} } } }) { + ${Post.plural}(where: { testString: "${testString}", likesAggregate: { node: { someBigInt_GTE: ${bigInt} } } }) { testString likes { testString @@ -225,7 +202,7 @@ describe("aggregations-where-node-bigint", () => { expect(gqlResult.errors).toBeUndefined(); - expect((gqlResult.data as any).posts).toEqual([ + expect((gqlResult.data as any)[Post.plural]).toEqual([ { testString, likes: [{ testString, someBigInt: bigInt }], @@ -239,18 +216,6 @@ describe("aggregations-where-node-bigint", () => { test("should return posts where a like BigInt is LT than", async () => { const session = await neo4j.getSession(); - const typeDefs = ` - type User { - testString: String! - someBigInt: BigInt - } - - type Post { - testString: String! - likes: [User!]! @relationship(type: "LIKES", direction: IN) - } - `; - const testString = generate({ charset: "alphabetic", readable: true, @@ -258,19 +223,17 @@ describe("aggregations-where-node-bigint", () => { const someBigIntLT = `${bigInt}1`; - const neoSchema = new Neo4jGraphQL({ typeDefs }); - try { await session.run( ` - CREATE (:Post {testString: "${testString}"})<-[:LIKES]-(:User {testString: "${testString}", someBigInt: toInteger(${bigInt})}) - CREATE (:Post {testString: "${testString}"}) + CREATE (:${Post} {testString: "${testString}"})<-[:LIKES]-(:${User} {testString: "${testString}", someBigInt: toInteger(${bigInt})}) + CREATE (:${Post} {testString: "${testString}"}) ` ); const query = ` { - posts(where: { testString: "${testString}", likesAggregate: { node: { someBigInt_LT: ${someBigIntLT} } } }) { + ${Post.plural}(where: { testString: "${testString}", likesAggregate: { node: { someBigInt_LT: ${someBigIntLT} } } }) { testString likes { testString @@ -292,7 +255,7 @@ describe("aggregations-where-node-bigint", () => { expect(gqlResult.errors).toBeUndefined(); - expect((gqlResult.data as any).posts).toEqual([ + expect((gqlResult.data as any)[Post.plural]).toEqual([ { testString, likes: [{ testString, someBigInt: bigInt }], @@ -306,36 +269,22 @@ describe("aggregations-where-node-bigint", () => { test("should return posts where a like BigInt is LTE than", async () => { const session = await neo4j.getSession(); - const typeDefs = ` - type User { - testString: String! - someBigInt: BigInt - } - - type Post { - testString: String! - likes: [User!]! @relationship(type: "LIKES", direction: IN) - } - `; - const testString = generate({ charset: "alphabetic", readable: true, }); - const neoSchema = new Neo4jGraphQL({ typeDefs }); - try { await session.run( ` - CREATE (:Post {testString: "${testString}"})<-[:LIKES]-(:User {testString: "${testString}", someBigInt: toInteger(${bigInt})}) - CREATE (:Post {testString: "${testString}"}) + CREATE (:${Post} {testString: "${testString}"})<-[:LIKES]-(:${User} {testString: "${testString}", someBigInt: toInteger(${bigInt})}) + CREATE (:${Post} {testString: "${testString}"}) ` ); const query = ` { - posts(where: { testString: "${testString}", likesAggregate: { node: { someBigInt_LTE: ${bigInt} } } }) { + ${Post.plural}(where: { testString: "${testString}", likesAggregate: { node: { someBigInt_LTE: ${bigInt} } } }) { testString likes { testString @@ -357,7 +306,7 @@ describe("aggregations-where-node-bigint", () => { expect(gqlResult.errors).toBeUndefined(); - expect((gqlResult.data as any).posts).toEqual([ + expect((gqlResult.data as any)[Post.plural]).toEqual([ { testString, likes: [{ testString, someBigInt: bigInt }], diff --git a/packages/graphql/tests/integration/aggregations/where/node/datetime.int.test.ts b/packages/graphql/tests/integration/aggregations/where/node/datetime.int.test.ts index 09325fcc80..4270cf807f 100644 --- a/packages/graphql/tests/integration/aggregations/where/node/datetime.int.test.ts +++ b/packages/graphql/tests/integration/aggregations/where/node/datetime.int.test.ts @@ -17,19 +17,37 @@ * limitations under the License. */ -import type { Driver } from "neo4j-driver"; import { graphql } from "graphql"; +import type { Driver } from "neo4j-driver"; import { generate } from "randomstring"; -import Neo4jHelper from "../../../neo4j"; import { Neo4jGraphQL } from "../../../../../src/classes"; +import { UniqueType } from "../../../../utils/graphql-types"; +import Neo4jHelper from "../../../neo4j"; describe("aggregations-where-node-datetime", () => { let driver: Driver; let neo4j: Neo4jHelper; + let neoSchema: Neo4jGraphQL; + let User: UniqueType; + let Post: UniqueType; beforeAll(async () => { neo4j = new Neo4jHelper(); driver = await neo4j.getDriver(); + User = new UniqueType("User"); + Post = new UniqueType("Post"); + const typeDefs = ` + type ${User} { + testString: String! + someDateTime: DateTime! + } + + type ${Post} { + testString: String! + likes: [${User}!]! @relationship(type: "LIKES", direction: IN) + } + `; + neoSchema = new Neo4jGraphQL({ typeDefs }); }); afterAll(async () => { @@ -39,18 +57,6 @@ describe("aggregations-where-node-datetime", () => { test("should return posts where a like DateTime is EQUAL to", async () => { const session = await neo4j.getSession(); - const typeDefs = ` - type User { - testString: String! - someDateTime: DateTime! - } - - type Post { - testString: String! - likes: [User!]! @relationship(type: "LIKES", direction: IN) - } - `; - const testString = generate({ charset: "alphabetic", readable: true, @@ -58,19 +64,19 @@ describe("aggregations-where-node-datetime", () => { const someDateTime = new Date(); - const neoSchema = new Neo4jGraphQL({ typeDefs }); - try { await session.run( ` - CREATE (:Post {testString: "${testString}"})<-[:LIKES]-(:User {testString: "${testString}", someDateTime: dateTime("${someDateTime.toISOString()}")}) - CREATE (:Post {testString: "${testString}"}) + CREATE (:${Post} {testString: "${testString}"})<-[:LIKES]-(:${User} {testString: "${testString}", someDateTime: dateTime("${someDateTime.toISOString()}")}) + CREATE (:${Post} {testString: "${testString}"}) ` ); const query = ` { - posts(where: { testString: "${testString}", likesAggregate: { node: { someDateTime_EQUAL: "${someDateTime.toISOString()}" } } }) { + ${ + Post.plural + }(where: { testString: "${testString}", likesAggregate: { node: { someDateTime_EQUAL: "${someDateTime.toISOString()}" } } }) { testString likes { testString @@ -92,7 +98,7 @@ describe("aggregations-where-node-datetime", () => { expect(gqlResult.errors).toBeUndefined(); - expect((gqlResult.data as any).posts).toEqual([ + expect((gqlResult.data as any)[Post.plural]).toEqual([ { testString, likes: [{ testString, someDateTime: someDateTime.toISOString() }], @@ -106,18 +112,6 @@ describe("aggregations-where-node-datetime", () => { test("should return posts where a like DateTime is GT than", async () => { const session = await neo4j.getSession(); - const typeDefs = ` - type User { - testString: String! - someDateTime: DateTime! - } - - type Post { - testString: String! - likes: [User!]! @relationship(type: "LIKES", direction: IN) - } - `; - const testString = generate({ charset: "alphabetic", readable: true, @@ -127,19 +121,19 @@ describe("aggregations-where-node-datetime", () => { const someDateTimeGT = new Date(); someDateTimeGT.setDate(someDateTimeGT.getDate() - 1); - const neoSchema = new Neo4jGraphQL({ typeDefs }); - try { await session.run( ` - CREATE (:Post {testString: "${testString}"})<-[:LIKES]-(:User {testString: "${testString}", someDateTime: datetime("${someDateTime.toISOString()}")}) - CREATE (:Post {testString: "${testString}"}) + CREATE (:${Post} {testString: "${testString}"})<-[:LIKES]-(:${User} {testString: "${testString}", someDateTime: datetime("${someDateTime.toISOString()}")}) + CREATE (:${Post} {testString: "${testString}"}) ` ); const query = ` { - posts(where: { testString: "${testString}", likesAggregate: { node: { someDateTime_GT: "${someDateTimeGT.toISOString()}" } } }) { + ${ + Post.plural + }(where: { testString: "${testString}", likesAggregate: { node: { someDateTime_GT: "${someDateTimeGT.toISOString()}" } } }) { testString likes { testString @@ -161,7 +155,7 @@ describe("aggregations-where-node-datetime", () => { expect(gqlResult.errors).toBeUndefined(); - expect((gqlResult.data as any).posts).toEqual([ + expect((gqlResult.data as any)[Post.plural]).toEqual([ { testString, likes: [{ testString, someDateTime: someDateTime.toISOString() }], @@ -175,18 +169,6 @@ describe("aggregations-where-node-datetime", () => { test("should return posts where a like DateTime is GTE than", async () => { const session = await neo4j.getSession(); - const typeDefs = ` - type User { - testString: String! - someDateTime: DateTime! - } - - type Post { - testString: String! - likes: [User!]! @relationship(type: "LIKES", direction: IN) - } - `; - const testString = generate({ charset: "alphabetic", readable: true, @@ -194,19 +176,19 @@ describe("aggregations-where-node-datetime", () => { const someDateTime = new Date(); - const neoSchema = new Neo4jGraphQL({ typeDefs }); - try { await session.run( ` - CREATE (:Post {testString: "${testString}"})<-[:LIKES]-(:User {testString: "${testString}", someDateTime: datetime("${someDateTime.toISOString()}")}) - CREATE (:Post {testString: "${testString}"}) + CREATE (:${Post} {testString: "${testString}"})<-[:LIKES]-(:${User} {testString: "${testString}", someDateTime: datetime("${someDateTime.toISOString()}")}) + CREATE (:${Post} {testString: "${testString}"}) ` ); const query = ` { - posts(where: { testString: "${testString}", likesAggregate: { node: { someDateTime_GTE: "${someDateTime.toISOString()}" } } }) { + ${ + Post.plural + }(where: { testString: "${testString}", likesAggregate: { node: { someDateTime_GTE: "${someDateTime.toISOString()}" } } }) { testString likes { testString @@ -228,7 +210,7 @@ describe("aggregations-where-node-datetime", () => { expect(gqlResult.errors).toBeUndefined(); - expect((gqlResult.data as any).posts).toEqual([ + expect((gqlResult.data as any)[Post.plural]).toEqual([ { testString, likes: [{ testString, someDateTime: someDateTime.toISOString() }], @@ -242,18 +224,6 @@ describe("aggregations-where-node-datetime", () => { test("should return posts where a like DateTime is LT than", async () => { const session = await neo4j.getSession(); - const typeDefs = ` - type User { - testString: String! - someDateTime: DateTime! - } - - type Post { - testString: String! - likes: [User!]! @relationship(type: "LIKES", direction: IN) - } - `; - const testString = generate({ charset: "alphabetic", readable: true, @@ -263,19 +233,19 @@ describe("aggregations-where-node-datetime", () => { const someDateTimeLT = new Date(); someDateTimeLT.setDate(someDateTimeLT.getDate() + 1); - const neoSchema = new Neo4jGraphQL({ typeDefs }); - try { await session.run( ` - CREATE (:Post {testString: "${testString}"})<-[:LIKES]-(:User {testString: "${testString}", someDateTime: datetime("${someDateTime.toISOString()}")}) - CREATE (:Post {testString: "${testString}"}) + CREATE (:${Post} {testString: "${testString}"})<-[:LIKES]-(:${User} {testString: "${testString}", someDateTime: datetime("${someDateTime.toISOString()}")}) + CREATE (:${Post} {testString: "${testString}"}) ` ); const query = ` { - posts(where: { testString: "${testString}", likesAggregate: { node: { someDateTime_LT: "${someDateTimeLT.toISOString()}" } } }) { + ${ + Post.plural + }(where: { testString: "${testString}", likesAggregate: { node: { someDateTime_LT: "${someDateTimeLT.toISOString()}" } } }) { testString likes { testString @@ -297,7 +267,7 @@ describe("aggregations-where-node-datetime", () => { expect(gqlResult.errors).toBeUndefined(); - expect((gqlResult.data as any).posts).toEqual([ + expect((gqlResult.data as any)[Post.plural]).toEqual([ { testString, likes: [{ testString, someDateTime: someDateTime.toISOString() }], @@ -311,18 +281,6 @@ describe("aggregations-where-node-datetime", () => { test("should return posts where a like DateTime is LTE than", async () => { const session = await neo4j.getSession(); - const typeDefs = ` - type User { - testString: String! - someDateTime: DateTime! - } - - type Post { - testString: String! - likes: [User!]! @relationship(type: "LIKES", direction: IN) - } - `; - const testString = generate({ charset: "alphabetic", readable: true, @@ -330,19 +288,19 @@ describe("aggregations-where-node-datetime", () => { const someDateTime = new Date(); - const neoSchema = new Neo4jGraphQL({ typeDefs }); - try { await session.run( ` - CREATE (:Post {testString: "${testString}"})<-[:LIKES]-(:User {testString: "${testString}", someDateTime: datetime("${someDateTime.toISOString()}")}) - CREATE (:Post {testString: "${testString}"}) + CREATE (:${Post} {testString: "${testString}"})<-[:LIKES]-(:${User} {testString: "${testString}", someDateTime: datetime("${someDateTime.toISOString()}")}) + CREATE (:${Post} {testString: "${testString}"}) ` ); const query = ` { - posts(where: { testString: "${testString}", likesAggregate: { node: { someDateTime_LTE: "${someDateTime.toISOString()}" } } }) { + ${ + Post.plural + }(where: { testString: "${testString}", likesAggregate: { node: { someDateTime_LTE: "${someDateTime.toISOString()}" } } }) { testString likes { testString @@ -364,7 +322,7 @@ describe("aggregations-where-node-datetime", () => { expect(gqlResult.errors).toBeUndefined(); - expect((gqlResult.data as any).posts).toEqual([ + expect((gqlResult.data as any)[Post.plural]).toEqual([ { testString, likes: [{ testString, someDateTime: someDateTime.toISOString() }], diff --git a/packages/graphql/tests/integration/aggregations/where/node/float.int.test.ts b/packages/graphql/tests/integration/aggregations/where/node/float.int.test.ts index b03b6ed052..58c20b1cfd 100644 --- a/packages/graphql/tests/integration/aggregations/where/node/float.int.test.ts +++ b/packages/graphql/tests/integration/aggregations/where/node/float.int.test.ts @@ -17,19 +17,37 @@ * limitations under the License. */ -import type { Driver } from "neo4j-driver"; import { graphql } from "graphql"; +import type { Driver } from "neo4j-driver"; import { generate } from "randomstring"; -import Neo4jHelper from "../../../neo4j"; import { Neo4jGraphQL } from "../../../../../src/classes"; +import { UniqueType } from "../../../../utils/graphql-types"; +import Neo4jHelper from "../../../neo4j"; describe("aggregations-where-node-float", () => { let driver: Driver; let neo4j: Neo4jHelper; + let neoSchema: Neo4jGraphQL; + let User: UniqueType; + let Post: UniqueType; beforeAll(async () => { neo4j = new Neo4jHelper(); driver = await neo4j.getDriver(); + User = new UniqueType("User"); + Post = new UniqueType("Post"); + const typeDefs = ` + type ${User} { + testString: String! + someFloat: Float! + } + + type ${Post} { + testString: String! + likes: [${User}!]! @relationship(type: "LIKES", direction: IN) + } + `; + neoSchema = new Neo4jGraphQL({ typeDefs }); }); afterAll(async () => { @@ -39,18 +57,6 @@ describe("aggregations-where-node-float", () => { test("should return posts where a like Float is EQUAL to", async () => { const session = await neo4j.getSession(); - const typeDefs = ` - type User { - testString: String! - someFloat: Float! - } - - type Post { - testString: String! - likes: [User!]! @relationship(type: "LIKES", direction: IN) - } - `; - const testString = generate({ charset: "alphabetic", readable: true, @@ -58,19 +64,17 @@ describe("aggregations-where-node-float", () => { const someFloat = Math.random() * Math.random() + 10; - const neoSchema = new Neo4jGraphQL({ typeDefs }); - try { await session.run( ` - CREATE (:Post {testString: "${testString}"})<-[:LIKES]-(:User {testString: "${testString}", someFloat: ${someFloat}}) - CREATE (:Post {testString: "${testString}"}) + CREATE (:${Post} {testString: "${testString}"})<-[:LIKES]-(:${User} {testString: "${testString}", someFloat: ${someFloat}}) + CREATE (:${Post} {testString: "${testString}"}) ` ); const query = ` { - posts(where: { testString: "${testString}", likesAggregate: { node: { someFloat_EQUAL: ${someFloat} } } }) { + ${Post.plural}(where: { testString: "${testString}", likesAggregate: { node: { someFloat_EQUAL: ${someFloat} } } }) { testString likes { testString @@ -92,7 +96,7 @@ describe("aggregations-where-node-float", () => { expect(gqlResult.errors).toBeUndefined(); - expect((gqlResult.data as any).posts).toEqual([ + expect((gqlResult.data as any)[Post.plural]).toEqual([ { testString, likes: [{ testString, someFloat }], @@ -106,18 +110,6 @@ describe("aggregations-where-node-float", () => { test("should return posts where a like Float is GT than", async () => { const session = await neo4j.getSession(); - const typeDefs = ` - type User { - testString: String! - someFloat: Float! - } - - type Post { - testString: String! - likes: [User!]! @relationship(type: "LIKES", direction: IN) - } - `; - const testString = generate({ charset: "alphabetic", readable: true, @@ -126,19 +118,17 @@ describe("aggregations-where-node-float", () => { const someFloat = Math.random() * Math.random() + 10; const someFloatGt = someFloat - 0.1; - const neoSchema = new Neo4jGraphQL({ typeDefs }); - try { await session.run( ` - CREATE (:Post {testString: "${testString}"})<-[:LIKES]-(:User {testString: "${testString}", someFloat: ${someFloat}}) - CREATE (:Post {testString: "${testString}"}) + CREATE (:${Post} {testString: "${testString}"})<-[:LIKES]-(:${User} {testString: "${testString}", someFloat: ${someFloat}}) + CREATE (:${Post} {testString: "${testString}"}) ` ); const query = ` { - posts(where: { testString: "${testString}", likesAggregate: { node: { someFloat_GT: ${someFloatGt} } } }) { + ${Post.plural}(where: { testString: "${testString}", likesAggregate: { node: { someFloat_GT: ${someFloatGt} } } }) { testString likes { testString @@ -160,7 +150,7 @@ describe("aggregations-where-node-float", () => { expect(gqlResult.errors).toBeUndefined(); - expect((gqlResult.data as any).posts).toEqual([ + expect((gqlResult.data as any)[Post.plural]).toEqual([ { testString, likes: [{ testString, someFloat }], @@ -174,18 +164,6 @@ describe("aggregations-where-node-float", () => { test("should return posts where a like Float is GTE than", async () => { const session = await neo4j.getSession(); - const typeDefs = ` - type User { - testString: String! - someFloat: Float! - } - - type Post { - testString: String! - likes: [User!]! @relationship(type: "LIKES", direction: IN) - } - `; - const testString = generate({ charset: "alphabetic", readable: true, @@ -193,19 +171,17 @@ describe("aggregations-where-node-float", () => { const someFloat = Math.random() * Math.random() + 10; - const neoSchema = new Neo4jGraphQL({ typeDefs }); - try { await session.run( ` - CREATE (:Post {testString: "${testString}"})<-[:LIKES]-(:User {testString: "${testString}", someFloat: ${someFloat}}) - CREATE (:Post {testString: "${testString}"}) + CREATE (:${Post} {testString: "${testString}"})<-[:LIKES]-(:${User} {testString: "${testString}", someFloat: ${someFloat}}) + CREATE (:${Post} {testString: "${testString}"}) ` ); const query = ` { - posts(where: { testString: "${testString}", likesAggregate: { node: { someFloat_GTE: ${someFloat} } } }) { + ${Post.plural}(where: { testString: "${testString}", likesAggregate: { node: { someFloat_GTE: ${someFloat} } } }) { testString likes { testString @@ -227,7 +203,7 @@ describe("aggregations-where-node-float", () => { expect(gqlResult.errors).toBeUndefined(); - expect((gqlResult.data as any).posts).toEqual([ + expect((gqlResult.data as any)[Post.plural]).toEqual([ { testString, likes: [{ testString, someFloat }], @@ -241,18 +217,6 @@ describe("aggregations-where-node-float", () => { test("should return posts where a like Float is LT than", async () => { const session = await neo4j.getSession(); - const typeDefs = ` - type User { - testString: String! - someFloat: Float! - } - - type Post { - testString: String! - likes: [User!]! @relationship(type: "LIKES", direction: IN) - } - `; - const testString = generate({ charset: "alphabetic", readable: true, @@ -261,19 +225,17 @@ describe("aggregations-where-node-float", () => { const someFloat = Math.random() * Math.random() + 10; const someFloatLT = someFloat + 0.1; - const neoSchema = new Neo4jGraphQL({ typeDefs }); - try { await session.run( ` - CREATE (:Post {testString: "${testString}"})<-[:LIKES]-(:User {testString: "${testString}", someFloat: ${someFloat}}) - CREATE (:Post {testString: "${testString}"}) + CREATE (:${Post} {testString: "${testString}"})<-[:LIKES]-(:${User} {testString: "${testString}", someFloat: ${someFloat}}) + CREATE (:${Post} {testString: "${testString}"}) ` ); const query = ` { - posts(where: { testString: "${testString}", likesAggregate: { node: { someFloat_LT: ${someFloatLT} } } }) { + ${Post.plural}(where: { testString: "${testString}", likesAggregate: { node: { someFloat_LT: ${someFloatLT} } } }) { testString likes { testString @@ -295,7 +257,7 @@ describe("aggregations-where-node-float", () => { expect(gqlResult.errors).toBeUndefined(); - expect((gqlResult.data as any).posts).toEqual([ + expect((gqlResult.data as any)[Post.plural]).toEqual([ { testString, likes: [{ testString, someFloat }], @@ -309,18 +271,6 @@ describe("aggregations-where-node-float", () => { test("should return posts where a like Float is LTE than", async () => { const session = await neo4j.getSession(); - const typeDefs = ` - type User { - testString: String! - someFloat: Float! - } - - type Post { - testString: String! - likes: [User!]! @relationship(type: "LIKES", direction: IN) - } - `; - const testString = generate({ charset: "alphabetic", readable: true, @@ -328,19 +278,17 @@ describe("aggregations-where-node-float", () => { const someFloat = Math.random() * Math.random() + 10; - const neoSchema = new Neo4jGraphQL({ typeDefs }); - try { await session.run( ` - CREATE (:Post {testString: "${testString}"})<-[:LIKES]-(:User {testString: "${testString}", someFloat: ${someFloat}}) - CREATE (:Post {testString: "${testString}"}) + CREATE (:${Post} {testString: "${testString}"})<-[:LIKES]-(:${User} {testString: "${testString}", someFloat: ${someFloat}}) + CREATE (:${Post} {testString: "${testString}"}) ` ); const query = ` { - posts(where: { testString: "${testString}", likesAggregate: { node: { someFloat_LTE: ${someFloat} } } }) { + ${Post.plural}(where: { testString: "${testString}", likesAggregate: { node: { someFloat_LTE: ${someFloat} } } }) { testString likes { testString @@ -362,7 +310,7 @@ describe("aggregations-where-node-float", () => { expect(gqlResult.errors).toBeUndefined(); - expect((gqlResult.data as any).posts).toEqual([ + expect((gqlResult.data as any)[Post.plural]).toEqual([ { testString, likes: [{ testString, someFloat }], diff --git a/packages/graphql/tests/integration/aggregations/where/node/id.int.test.ts b/packages/graphql/tests/integration/aggregations/where/node/id.int.test.ts index b13740a132..6c59eb9ea8 100644 --- a/packages/graphql/tests/integration/aggregations/where/node/id.int.test.ts +++ b/packages/graphql/tests/integration/aggregations/where/node/id.int.test.ts @@ -17,19 +17,38 @@ * limitations under the License. */ -import type { Driver } from "neo4j-driver"; import { graphql } from "graphql"; +import type { Driver } from "neo4j-driver"; import { generate } from "randomstring"; -import Neo4jHelper from "../../../neo4j"; import { Neo4jGraphQL } from "../../../../../src/classes"; +import { UniqueType } from "../../../../utils/graphql-types"; +import Neo4jHelper from "../../../neo4j"; describe("aggregations-where-node-id", () => { let driver: Driver; let neo4j: Neo4jHelper; + let neoSchema: Neo4jGraphQL; + let User: UniqueType; + let Post: UniqueType; beforeAll(async () => { neo4j = new Neo4jHelper(); driver = await neo4j.getDriver(); + User = new UniqueType("User"); + Post = new UniqueType("Post"); + + const typeDefs = ` + type ${User} { + id: ID + testString: String! + } + + type ${Post} { + testString: String! + likes: [${User}!]! @relationship(type: "LIKES", direction: IN) + } + `; + neoSchema = new Neo4jGraphQL({ typeDefs }); }); afterAll(async () => { @@ -39,18 +58,6 @@ describe("aggregations-where-node-id", () => { test("should return posts where a like ID is EQUAL to", async () => { const session = await neo4j.getSession(); - const typeDefs = ` - type User { - id: ID - testString: String! - } - - type Post { - testString: String! - likes: [User!]! @relationship(type: "LIKES", direction: IN) - } - `; - const testString = generate({ charset: "alphabetic", readable: true, @@ -61,19 +68,17 @@ describe("aggregations-where-node-id", () => { readable: true, }); - const neoSchema = new Neo4jGraphQL({ typeDefs }); - try { await session.run( ` - CREATE (:Post {testString: "${testString}"})<-[:LIKES]-(:User {testString: "${testString}", id: "${testId}"}) - CREATE (:Post {testString: "${testString}"}) + CREATE (:${Post} {testString: "${testString}"})<-[:LIKES]-(:${User} {testString: "${testString}", id: "${testId}"}) + CREATE (:${Post} {testString: "${testString}"}) ` ); const query = ` { - posts(where: { testString: "${testString}", likesAggregate: { node: { id_EQUAL: "${testId}" } } }) { + ${Post.plural}(where: { testString: "${testString}", likesAggregate: { node: { id_EQUAL: "${testId}" } } }) { testString likes { id @@ -95,7 +100,7 @@ describe("aggregations-where-node-id", () => { expect(gqlResult.errors).toBeUndefined(); - expect((gqlResult.data as any).posts).toEqual([ + expect((gqlResult.data as any)[Post.plural]).toEqual([ { testString, likes: [{ id: testId, testString }], diff --git a/packages/graphql/tests/integration/aggregations/where/node/int.int.test.ts b/packages/graphql/tests/integration/aggregations/where/node/int.int.test.ts index f643a5713f..e78e516594 100644 --- a/packages/graphql/tests/integration/aggregations/where/node/int.int.test.ts +++ b/packages/graphql/tests/integration/aggregations/where/node/int.int.test.ts @@ -22,15 +22,33 @@ import { graphql } from "graphql"; import type { Driver } from "neo4j-driver"; import { generate } from "randomstring"; import { Neo4jGraphQL } from "../../../../../src/classes"; +import { UniqueType } from "../../../../utils/graphql-types"; import Neo4jHelper from "../../../neo4j"; describe("aggregations-where-node-int", () => { let driver: Driver; let neo4j: Neo4jHelper; + let neoSchema: Neo4jGraphQL; + let User: UniqueType; + let Post: UniqueType; beforeAll(async () => { neo4j = new Neo4jHelper(); driver = await neo4j.getDriver(); + User = new UniqueType("User"); + Post = new UniqueType("Post"); + const typeDefs = ` + type ${User} { + testString: String! + someInt: Int! + } + + type ${Post} { + testString: String! + likes: [${User}!]! @relationship(type: "LIKES", direction: IN) + } + `; + neoSchema = new Neo4jGraphQL({ typeDefs }); }); afterAll(async () => { @@ -40,18 +58,6 @@ describe("aggregations-where-node-int", () => { test("should return posts where a like Int is EQUAL to", async () => { const session = await neo4j.getSession(); - const typeDefs = ` - type User { - testString: String! - someInt: Int! - } - - type Post { - testString: String! - likes: [User!]! @relationship(type: "LIKES", direction: IN) - } - `; - const testString = generate({ charset: "alphabetic", readable: true, @@ -59,19 +65,17 @@ describe("aggregations-where-node-int", () => { const someInt = Number(faker.number.int({ max: 100000 })); - const neoSchema = new Neo4jGraphQL({ typeDefs }); - try { await session.run( ` - CREATE (:Post {testString: "${testString}"})<-[:LIKES]-(:User {testString: "${testString}", someInt: ${someInt}}) - CREATE (:Post {testString: "${testString}"}) + CREATE (:${Post} {testString: "${testString}"})<-[:LIKES]-(:${User} {testString: "${testString}", someInt: ${someInt}}) + CREATE (:${Post} {testString: "${testString}"}) ` ); const query = ` { - posts(where: { testString: "${testString}", likesAggregate: { node: { someInt_EQUAL: ${someInt} } } }) { + ${Post.plural}(where: { testString: "${testString}", likesAggregate: { node: { someInt_EQUAL: ${someInt} } } }) { testString likes { testString @@ -89,7 +93,7 @@ describe("aggregations-where-node-int", () => { expect(gqlResult.errors).toBeUndefined(); - expect((gqlResult.data as any).posts).toEqual([ + expect((gqlResult.data as any)[Post.plural]).toEqual([ { testString, likes: [{ testString, someInt }], @@ -103,18 +107,6 @@ describe("aggregations-where-node-int", () => { test("should return posts where a like Float is GT than", async () => { const session = await neo4j.getSession(); - const typeDefs = ` - type User { - testString: String! - someInt: Int! - } - - type Post { - testString: String! - likes: [User!]! @relationship(type: "LIKES", direction: IN) - } - `; - const testString = generate({ charset: "alphabetic", readable: true, @@ -123,19 +115,17 @@ describe("aggregations-where-node-int", () => { const someInt = Number(faker.number.int({ max: 100000 })); const someIntGt = someInt - 1; - const neoSchema = new Neo4jGraphQL({ typeDefs }); - try { await session.run( ` - CREATE (:Post {testString: "${testString}"})<-[:LIKES]-(:User {testString: "${testString}", someInt: ${someInt}}) - CREATE (:Post {testString: "${testString}"}) + CREATE (:${Post} {testString: "${testString}"})<-[:LIKES]-(:${User} {testString: "${testString}", someInt: ${someInt}}) + CREATE (:${Post} {testString: "${testString}"}) ` ); const query = ` { - posts(where: { testString: "${testString}", likesAggregate: { node: { someInt_GT: ${someIntGt} } } }) { + ${Post.plural}(where: { testString: "${testString}", likesAggregate: { node: { someInt_GT: ${someIntGt} } } }) { testString likes { testString @@ -153,7 +143,7 @@ describe("aggregations-where-node-int", () => { expect(gqlResult.errors).toBeUndefined(); - expect((gqlResult.data as any).posts).toEqual([ + expect((gqlResult.data as any)[Post.plural]).toEqual([ { testString, likes: [{ testString, someInt }], @@ -167,18 +157,6 @@ describe("aggregations-where-node-int", () => { test("should return posts where a like Float is GTE than", async () => { const session = await neo4j.getSession(); - const typeDefs = ` - type User { - testString: String! - someInt: Int! - } - - type Post { - testString: String! - likes: [User!]! @relationship(type: "LIKES", direction: IN) - } - `; - const testString = generate({ charset: "alphabetic", readable: true, @@ -186,19 +164,17 @@ describe("aggregations-where-node-int", () => { const someInt = Number(faker.number.int({ max: 100000 })); - const neoSchema = new Neo4jGraphQL({ typeDefs }); - try { await session.run( ` - CREATE (:Post {testString: "${testString}"})<-[:LIKES]-(:User {testString: "${testString}", someInt: ${someInt}}) - CREATE (:Post {testString: "${testString}"}) + CREATE (:${Post} {testString: "${testString}"})<-[:LIKES]-(:${User} {testString: "${testString}", someInt: ${someInt}}) + CREATE (:${Post} {testString: "${testString}"}) ` ); const query = ` { - posts(where: { testString: "${testString}", likesAggregate: { node: { someInt_GTE: ${someInt} } } }) { + ${Post.plural}(where: { testString: "${testString}", likesAggregate: { node: { someInt_GTE: ${someInt} } } }) { testString likes { testString @@ -216,7 +192,7 @@ describe("aggregations-where-node-int", () => { expect(gqlResult.errors).toBeUndefined(); - expect((gqlResult.data as any).posts).toEqual([ + expect((gqlResult.data as any)[Post.plural]).toEqual([ { testString, likes: [{ testString, someInt }], @@ -230,18 +206,6 @@ describe("aggregations-where-node-int", () => { test("should return posts where a like Float is LT than", async () => { const session = await neo4j.getSession(); - const typeDefs = ` - type User { - testString: String! - someInt: Int! - } - - type Post { - testString: String! - likes: [User!]! @relationship(type: "LIKES", direction: IN) - } - `; - const testString = generate({ charset: "alphabetic", readable: true, @@ -250,19 +214,17 @@ describe("aggregations-where-node-int", () => { const someInt = Number(faker.number.int({ max: 100000 })); const someIntLT = someInt + 1; - const neoSchema = new Neo4jGraphQL({ typeDefs }); - try { await session.run( ` - CREATE (:Post {testString: "${testString}"})<-[:LIKES]-(:User {testString: "${testString}", someInt: ${someInt}}) - CREATE (:Post {testString: "${testString}"}) + CREATE (:${Post} {testString: "${testString}"})<-[:LIKES]-(:${User} {testString: "${testString}", someInt: ${someInt}}) + CREATE (:${Post} {testString: "${testString}"}) ` ); const query = ` { - posts(where: { testString: "${testString}", likesAggregate: { node: { someInt_LT: ${someIntLT} } } }) { + ${Post.plural}(where: { testString: "${testString}", likesAggregate: { node: { someInt_LT: ${someIntLT} } } }) { testString likes { testString @@ -280,7 +242,7 @@ describe("aggregations-where-node-int", () => { expect(gqlResult.errors).toBeUndefined(); - expect((gqlResult.data as any).posts).toEqual([ + expect((gqlResult.data as any)[Post.plural]).toEqual([ { testString, likes: [{ testString, someInt }], @@ -294,18 +256,6 @@ describe("aggregations-where-node-int", () => { test("should return posts where a like Float is LTE than", async () => { const session = await neo4j.getSession(); - const typeDefs = ` - type User { - testString: String! - someInt: Int! - } - - type Post { - testString: String! - likes: [User!]! @relationship(type: "LIKES", direction: IN) - } - `; - const testString = generate({ charset: "alphabetic", readable: true, @@ -313,19 +263,17 @@ describe("aggregations-where-node-int", () => { const someInt = Number(faker.number.int({ max: 100000 })); - const neoSchema = new Neo4jGraphQL({ typeDefs }); - try { await session.run( ` - CREATE (:Post {testString: "${testString}"})<-[:LIKES]-(:User {testString: "${testString}", someInt: ${someInt}}) - CREATE (:Post {testString: "${testString}"}) + CREATE (:${Post} {testString: "${testString}"})<-[:LIKES]-(:${User} {testString: "${testString}", someInt: ${someInt}}) + CREATE (:${Post} {testString: "${testString}"}) ` ); const query = ` { - posts(where: { testString: "${testString}", likesAggregate: { node: { someInt_LTE: ${someInt} } } }) { + ${Post.plural}(where: { testString: "${testString}", likesAggregate: { node: { someInt_LTE: ${someInt} } } }) { testString likes { testString @@ -343,7 +291,7 @@ describe("aggregations-where-node-int", () => { expect(gqlResult.errors).toBeUndefined(); - expect((gqlResult.data as any).posts).toEqual([ + expect((gqlResult.data as any)[Post.plural]).toEqual([ { testString, likes: [{ testString, someInt }], @@ -355,18 +303,6 @@ describe("aggregations-where-node-int", () => { }); describe("AVERAGE", () => { - const typeDefs = ` - type User { - testString: String! - someInt: Int! - } - - type Post { - testString: String! - likes: [User!]! @relationship(type: "LIKES", direction: IN) - } - `; - const someInt1 = 1; const someInt2 = 2; const someInt3 = 3; @@ -381,22 +317,20 @@ describe("aggregations-where-node-int", () => { const avg = (someInt1 + someInt2 + someInt3) / 3; - const neoSchema = new Neo4jGraphQL({ typeDefs }); - try { await session.run( ` - CREATE (p:Post {testString: "${testString}"}) - CREATE (p)<-[:LIKES]-(:User {testString: "${testString}", someInt: ${someInt1}}) - CREATE (p)<-[:LIKES]-(:User {testString: "${testString}", someInt: ${someInt2}}) - CREATE (p)<-[:LIKES]-(:User {testString: "${testString}", someInt: ${someInt3}}) - CREATE (:Post {testString: "${testString}"}) + CREATE (p:${Post} {testString: "${testString}"}) + CREATE (p)<-[:LIKES]-(:${User} {testString: "${testString}", someInt: ${someInt1}}) + CREATE (p)<-[:LIKES]-(:${User} {testString: "${testString}", someInt: ${someInt2}}) + CREATE (p)<-[:LIKES]-(:${User} {testString: "${testString}", someInt: ${someInt3}}) + CREATE (:${Post} {testString: "${testString}"}) ` ); const query = ` { - posts(where: { testString: "${testString}", likesAggregate: { node: { someInt_AVERAGE_EQUAL: ${avg} } } }) { + ${Post.plural}(where: { testString: "${testString}", likesAggregate: { node: { someInt_AVERAGE_EQUAL: ${avg} } } }) { testString likes { testString @@ -414,7 +348,7 @@ describe("aggregations-where-node-int", () => { expect(gqlResult.errors).toBeUndefined(); - const [post] = (gqlResult.data as any).posts as any[]; + const [post] = (gqlResult.data as any)[Post.plural] as any[]; expect(post.testString).toEqual(testString); expect(post.likes).toHaveLength(3); } finally { @@ -433,22 +367,20 @@ describe("aggregations-where-node-int", () => { const avg = (someInt1 + someInt2 + someInt3) / 3; const avgGT = avg - 1; - const neoSchema = new Neo4jGraphQL({ typeDefs }); - try { await session.run( ` - CREATE (p:Post {testString: "${testString}"}) - CREATE (p)<-[:LIKES]-(:User {testString: "${testString}", someInt: ${someInt1}}) - CREATE (p)<-[:LIKES]-(:User {testString: "${testString}", someInt: ${someInt2}}) - CREATE (p)<-[:LIKES]-(:User {testString: "${testString}", someInt: ${someInt3}}) - CREATE (:Post {testString: "${testString}"}) + CREATE (p:${Post} {testString: "${testString}"}) + CREATE (p)<-[:LIKES]-(:${User} {testString: "${testString}", someInt: ${someInt1}}) + CREATE (p)<-[:LIKES]-(:${User} {testString: "${testString}", someInt: ${someInt2}}) + CREATE (p)<-[:LIKES]-(:${User} {testString: "${testString}", someInt: ${someInt3}}) + CREATE (:${Post} {testString: "${testString}"}) ` ); const query = ` { - posts(where: { testString: "${testString}", likesAggregate: { node: { someInt_AVERAGE_GT: ${avgGT} } } }) { + ${Post.plural}(where: { testString: "${testString}", likesAggregate: { node: { someInt_AVERAGE_GT: ${avgGT} } } }) { testString likes { testString @@ -466,7 +398,7 @@ describe("aggregations-where-node-int", () => { expect(gqlResult.errors).toBeUndefined(); - const [post] = (gqlResult.data as any).posts as any[]; + const [post] = (gqlResult.data as any)[Post.plural] as any[]; expect(post.testString).toEqual(testString); expect(post.likes).toHaveLength(3); } finally { @@ -484,22 +416,20 @@ describe("aggregations-where-node-int", () => { const avg = (someInt1 + someInt2 + someInt3) / 3; - const neoSchema = new Neo4jGraphQL({ typeDefs }); - try { await session.run( ` - CREATE (p:Post {testString: "${testString}"}) - CREATE (p)<-[:LIKES]-(:User {testString: "${testString}", someInt: ${someInt1}}) - CREATE (p)<-[:LIKES]-(:User {testString: "${testString}", someInt: ${someInt2}}) - CREATE (p)<-[:LIKES]-(:User {testString: "${testString}", someInt: ${someInt3}}) - CREATE (:Post {testString: "${testString}"}) + CREATE (p:${Post} {testString: "${testString}"}) + CREATE (p)<-[:LIKES]-(:${User} {testString: "${testString}", someInt: ${someInt1}}) + CREATE (p)<-[:LIKES]-(:${User} {testString: "${testString}", someInt: ${someInt2}}) + CREATE (p)<-[:LIKES]-(:${User} {testString: "${testString}", someInt: ${someInt3}}) + CREATE (:${Post} {testString: "${testString}"}) ` ); const query = ` { - posts(where: { testString: "${testString}", likesAggregate: { node: { someInt_AVERAGE_GTE: ${avg} } } }) { + ${Post.plural}(where: { testString: "${testString}", likesAggregate: { node: { someInt_AVERAGE_GTE: ${avg} } } }) { testString likes { testString @@ -517,7 +447,7 @@ describe("aggregations-where-node-int", () => { expect(gqlResult.errors).toBeUndefined(); - const [post] = (gqlResult.data as any).posts as any[]; + const [post] = (gqlResult.data as any)[Post.plural] as any[]; expect(post.testString).toEqual(testString); expect(post.likes).toHaveLength(3); } finally { @@ -536,22 +466,20 @@ describe("aggregations-where-node-int", () => { const avg = (someInt1 + someInt2 + someInt3) / 3; const avgLT = avg + 1; - const neoSchema = new Neo4jGraphQL({ typeDefs }); - try { await session.run( ` - CREATE (p:Post {testString: "${testString}"}) - CREATE (p)<-[:LIKES]-(:User {testString: "${testString}", someInt: ${someInt1}}) - CREATE (p)<-[:LIKES]-(:User {testString: "${testString}", someInt: ${someInt2}}) - CREATE (p)<-[:LIKES]-(:User {testString: "${testString}", someInt: ${someInt3}}) - CREATE (:Post {testString: "${testString}"}) + CREATE (p:${Post} {testString: "${testString}"}) + CREATE (p)<-[:LIKES]-(:${User} {testString: "${testString}", someInt: ${someInt1}}) + CREATE (p)<-[:LIKES]-(:${User} {testString: "${testString}", someInt: ${someInt2}}) + CREATE (p)<-[:LIKES]-(:${User} {testString: "${testString}", someInt: ${someInt3}}) + CREATE (:${Post} {testString: "${testString}"}) ` ); const query = ` { - posts(where: { testString: "${testString}", likesAggregate: { node: { someInt_AVERAGE_LT: ${avgLT} } } }) { + ${Post.plural}(where: { testString: "${testString}", likesAggregate: { node: { someInt_AVERAGE_LT: ${avgLT} } } }) { testString likes { testString @@ -569,7 +497,7 @@ describe("aggregations-where-node-int", () => { expect(gqlResult.errors).toBeUndefined(); - const [post] = (gqlResult.data as any).posts as any[]; + const [post] = (gqlResult.data as any)[Post.plural] as any[]; expect(post.testString).toEqual(testString); expect(post.likes).toHaveLength(3); } finally { @@ -587,22 +515,20 @@ describe("aggregations-where-node-int", () => { const avg = (someInt1 + someInt2 + someInt3) / 3; - const neoSchema = new Neo4jGraphQL({ typeDefs }); - try { await session.run( ` - CREATE (p:Post {testString: "${testString}"}) - CREATE (p)<-[:LIKES]-(:User {testString: "${testString}", someInt: ${someInt1}}) - CREATE (p)<-[:LIKES]-(:User {testString: "${testString}", someInt: ${someInt2}}) - CREATE (p)<-[:LIKES]-(:User {testString: "${testString}", someInt: ${someInt3}}) - CREATE (:Post {testString: "${testString}"}) + CREATE (p:${Post} {testString: "${testString}"}) + CREATE (p)<-[:LIKES]-(:${User} {testString: "${testString}", someInt: ${someInt1}}) + CREATE (p)<-[:LIKES]-(:${User} {testString: "${testString}", someInt: ${someInt2}}) + CREATE (p)<-[:LIKES]-(:${User} {testString: "${testString}", someInt: ${someInt3}}) + CREATE (:${Post} {testString: "${testString}"}) ` ); const query = ` { - posts(where: { testString: "${testString}", likesAggregate: { node: { someInt_AVERAGE_LTE: ${avg} } } }) { + ${Post.plural}(where: { testString: "${testString}", likesAggregate: { node: { someInt_AVERAGE_LTE: ${avg} } } }) { testString likes { testString @@ -620,7 +546,7 @@ describe("aggregations-where-node-int", () => { expect(gqlResult.errors).toBeUndefined(); - const [post] = (gqlResult.data as any).posts as any[]; + const [post] = (gqlResult.data as any)[Post.plural] as any[]; expect(post.testString).toEqual(testString); expect(post.likes).toHaveLength(3); } finally { @@ -633,18 +559,6 @@ describe("aggregations-where-node-int", () => { test("should return posts where the sum of like Int's is EQUAL to", async () => { const session = await neo4j.getSession(); - const typeDefs = ` - type User { - testString: String! - someInt: Int! - } - - type Post { - testString: String! - likes: [User!]! @relationship(type: "LIKES", direction: IN) - } - `; - const testString = generate({ charset: "alphabetic", readable: true, @@ -656,22 +570,20 @@ describe("aggregations-where-node-int", () => { const sum = someInt1 + someInt2 + someInt3; - const neoSchema = new Neo4jGraphQL({ typeDefs }); - try { await session.run( ` - CREATE (p:Post {testString: "${testString}"}) - CREATE (p)<-[:LIKES]-(:User {testString: "${testString}", someInt: ${someInt1}}) - CREATE (p)<-[:LIKES]-(:User {testString: "${testString}", someInt: ${someInt2}}) - CREATE (p)<-[:LIKES]-(:User {testString: "${testString}", someInt: ${someInt3}}) - CREATE (:Post {testString: "${testString}"}) + CREATE (p:${Post} {testString: "${testString}"}) + CREATE (p)<-[:LIKES]-(:${User} {testString: "${testString}", someInt: ${someInt1}}) + CREATE (p)<-[:LIKES]-(:${User} {testString: "${testString}", someInt: ${someInt2}}) + CREATE (p)<-[:LIKES]-(:${User} {testString: "${testString}", someInt: ${someInt3}}) + CREATE (:${Post} {testString: "${testString}"}) ` ); const query = ` { - posts(where: { testString: "${testString}", likesAggregate: { node: { someInt_SUM_EQUAL: ${sum} } } }) { + ${Post.plural}(where: { testString: "${testString}", likesAggregate: { node: { someInt_SUM_EQUAL: ${sum} } } }) { testString likes { testString @@ -689,7 +601,7 @@ describe("aggregations-where-node-int", () => { expect(gqlResult.errors).toBeUndefined(); - const [post] = (gqlResult.data as any).posts as any[]; + const [post] = (gqlResult.data as any)[Post.plural] as any[]; expect(post.testString).toEqual(testString); expect(post.likes).toHaveLength(3); } finally {