Skip to content

Commit 819ac7e

Browse files
Merge pull request #4839 from MacondoExpress/unique-type-chunk-int
Use UniqueType on integration/root test files
2 parents 6b547dd + 928a505 commit 819ac7e

11 files changed

+464
-521
lines changed

packages/graphql/tests/integration/aliasing.int.test.ts

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -17,43 +17,46 @@
1717
* limitations under the License.
1818
*/
1919

20-
import type { Driver } from "neo4j-driver";
2120
import type { GraphQLSchema } from "graphql";
2221
import { graphql } from "graphql";
22+
import type { Driver } from "neo4j-driver";
2323
import { generate } from "randomstring";
24-
import Neo4jHelper from "./neo4j";
2524
import { Neo4jGraphQL } from "../../src/classes";
26-
27-
const testLabel = generate({ charset: "alphabetic" });
25+
import { UniqueType } from "../utils/graphql-types";
26+
import Neo4jHelper from "./neo4j";
2827

2928
describe("Aliasing", () => {
3029
let driver: Driver;
3130
let neo4j: Neo4jHelper;
3231
let schema: GraphQLSchema;
33-
34-
const typeDefs = `
35-
type Movie {
36-
id: ID!
37-
budget: Int!
38-
boxOffice: Float!
39-
}
40-
`;
41-
42-
const id = generate({ readable: false });
43-
const budget = 63;
44-
const boxOffice = 465.3;
32+
let Movie: UniqueType;
33+
let id: string;
34+
let budget: number;
35+
let boxOffice: number;
4536

4637
beforeAll(async () => {
4738
neo4j = new Neo4jHelper();
4839
driver = await neo4j.getDriver();
4940
const session = await neo4j.getSession();
41+
Movie = new UniqueType("Movie");
42+
43+
const typeDefs = `
44+
type ${Movie} {
45+
id: ID!
46+
budget: Int!
47+
boxOffice: Float!
48+
}
49+
`;
50+
51+
id = generate({ readable: false });
52+
budget = 63;
53+
boxOffice = 465.3;
5054
const neoSchema = new Neo4jGraphQL({ typeDefs });
5155
schema = await neoSchema.getSchema();
5256
try {
5357
await session.run(
5458
`
55-
CREATE (movie:Movie)
56-
SET movie:${testLabel}
59+
CREATE (movie:${Movie})
5760
SET movie += $properties
5861
`,
5962
{
@@ -74,7 +77,7 @@ describe("Aliasing", () => {
7477
try {
7578
await session.run(
7679
`
77-
MATCH(node:${testLabel})
80+
MATCH(node:${Movie})
7881
DETACH DELETE node
7982
`
8083
);
@@ -87,7 +90,7 @@ describe("Aliasing", () => {
8790
test("should correctly alias an ID field", async () => {
8891
const query = `
8992
query ($id: ID!) {
90-
movies(where: { id: $id }) {
93+
${Movie.plural}(where: { id: $id }) {
9194
aliased: id
9295
budget
9396
boxOffice
@@ -103,7 +106,7 @@ describe("Aliasing", () => {
103106
});
104107

105108
expect(gqlResult.errors).toBeFalsy();
106-
expect((gqlResult?.data as any)?.movies[0]).toEqual({
109+
expect((gqlResult?.data as any)[Movie.plural][0]).toEqual({
107110
aliased: id,
108111
budget,
109112
boxOffice,
@@ -113,7 +116,7 @@ describe("Aliasing", () => {
113116
test("should correctly alias an Int field", async () => {
114117
const query = `
115118
query ($id: ID!) {
116-
movies(where: { id: $id }) {
119+
${Movie.plural}(where: { id: $id }) {
117120
id
118121
aliased: budget
119122
boxOffice
@@ -129,7 +132,7 @@ describe("Aliasing", () => {
129132
});
130133

131134
expect(gqlResult.errors).toBeFalsy();
132-
expect((gqlResult?.data as any)?.movies[0]).toEqual({
135+
expect((gqlResult?.data as any)[Movie.plural][0]).toEqual({
133136
id,
134137
aliased: budget,
135138
boxOffice,
@@ -139,7 +142,7 @@ describe("Aliasing", () => {
139142
test("should correctly alias an Float field", async () => {
140143
const query = `
141144
query ($id: ID!) {
142-
movies(where: { id: $id }) {
145+
${Movie.plural}(where: { id: $id }) {
143146
id
144147
budget
145148
aliased: boxOffice
@@ -155,7 +158,7 @@ describe("Aliasing", () => {
155158
});
156159

157160
expect(gqlResult.errors).toBeFalsy();
158-
expect((gqlResult?.data as any)?.movies[0]).toEqual({
161+
expect((gqlResult?.data as any)[Movie.plural][0]).toEqual({
159162
id,
160163
budget,
161164
aliased: boxOffice,

packages/graphql/tests/integration/composite-where.int.test.ts

Lines changed: 36 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,37 @@ import { graphql } from "graphql";
2121
import type { Driver } from "neo4j-driver";
2222
import { generate } from "randomstring";
2323
import { Neo4jGraphQL } from "../../src/classes";
24+
import { UniqueType } from "../utils/graphql-types";
2425
import Neo4jHelper from "./neo4j";
2526

2627
describe("composite-where", () => {
2728
let driver: Driver;
2829
let neo4j: Neo4jHelper;
30+
let neoSchema: Neo4jGraphQL;
31+
let Actor: UniqueType;
32+
let Movie: UniqueType;
2933

3034
beforeAll(async () => {
3135
neo4j = new Neo4jHelper();
3236
driver = await neo4j.getDriver();
37+
Actor = new UniqueType("Actor");
38+
Movie = new UniqueType("Movie");
39+
const typeDefs = `
40+
type ${Actor} {
41+
name: String
42+
}
43+
44+
type ${Movie} {
45+
id: ID!
46+
actors: [${Actor}!]! @relationship(type: "ACTED_IN", properties: "ActedIn", direction: IN)
47+
}
48+
49+
type ActedIn @relationshipProperties {
50+
screenTime: Int
51+
}
52+
`;
53+
54+
neoSchema = new Neo4jGraphQL({ typeDefs });
3355
});
3456

3557
afterAll(async () => {
@@ -40,23 +62,6 @@ describe("composite-where", () => {
4062
test("should use composite where to delete", async () => {
4163
const session = await neo4j.getSession();
4264

43-
const typeDefs = `
44-
type Actor {
45-
name: String
46-
}
47-
48-
type Movie {
49-
id: ID!
50-
actors: [Actor!]! @relationship(type: "ACTED_IN", properties: "ActedIn", direction: IN)
51-
}
52-
53-
type ActedIn @relationshipProperties {
54-
screenTime: Int
55-
}
56-
`;
57-
58-
const neoSchema = new Neo4jGraphQL({ typeDefs });
59-
6065
const actorName1 = generate({
6166
charset: "alphabetic",
6267
});
@@ -70,7 +75,7 @@ describe("composite-where", () => {
7075

7176
const query = `
7277
mutation($movieId: ID, $actorName1: String, $screenTime: Int) {
73-
updateMovies(
78+
${Movie.operations.update}(
7479
where: {
7580
id: $movieId
7681
}
@@ -87,7 +92,7 @@ describe("composite-where", () => {
8792
}
8893
}
8994
) {
90-
movies {
95+
${Movie.plural} {
9196
id
9297
actors {
9398
name
@@ -100,9 +105,9 @@ describe("composite-where", () => {
100105
try {
101106
await session.run(
102107
`
103-
CREATE (m:Movie {id: $movieId})
104-
CREATE (m)<-[:ACTED_IN {screenTime:$screenTime}]-(:Actor {name:$actorName1})
105-
CREATE (m)<-[:ACTED_IN {screenTime:$screenTime}]-(:Actor {name:$actorName2})
108+
CREATE (m:${Movie} {id: $movieId})
109+
CREATE (m)<-[:ACTED_IN {screenTime:$screenTime}]-(:${Actor} {name:$actorName1})
110+
CREATE (m)<-[:ACTED_IN {screenTime:$screenTime}]-(:${Actor} {name:$actorName2})
106111
`,
107112
{ movieId, screenTime, actorName1, actorName2 }
108113
);
@@ -116,8 +121,8 @@ describe("composite-where", () => {
116121

117122
expect(gqlResult.errors).toBeFalsy();
118123

119-
expect(gqlResult?.data?.updateMovies).toEqual({
120-
movies: [{ id: movieId, actors: [{ name: actorName2 }] }],
124+
expect(gqlResult?.data?.[Movie.operations.update]).toEqual({
125+
[Movie.plural]: [{ id: movieId, actors: [{ name: actorName2 }] }],
121126
});
122127
} finally {
123128
await session.close();
@@ -129,23 +134,6 @@ describe("composite-where", () => {
129134
test("should use composite where to delete", async () => {
130135
const session = await neo4j.getSession();
131136

132-
const typeDefs = `
133-
type Actor {
134-
name: String
135-
}
136-
137-
type Movie {
138-
id: ID!
139-
actors: [Actor!]! @relationship(type: "ACTED_IN", properties: "ActedIn", direction: IN)
140-
}
141-
142-
type ActedIn @relationshipProperties {
143-
screenTime: Int
144-
}
145-
`;
146-
147-
const neoSchema = new Neo4jGraphQL({ typeDefs });
148-
149137
const actorName1 = generate({
150138
charset: "alphabetic",
151139
});
@@ -159,7 +147,7 @@ describe("composite-where", () => {
159147

160148
const query = `
161149
mutation($movieId: ID, $actorName1: String, $screenTime: Int) {
162-
updateMovies(
150+
${Movie.operations.update}(
163151
where: {
164152
id: $movieId
165153
}
@@ -176,7 +164,7 @@ describe("composite-where", () => {
176164
}
177165
}
178166
) {
179-
movies {
167+
${Movie.plural} {
180168
id
181169
actors {
182170
name
@@ -189,9 +177,9 @@ describe("composite-where", () => {
189177
try {
190178
await session.run(
191179
`
192-
CREATE (m:Movie {id: $movieId})
193-
CREATE (m)<-[:ACTED_IN {screenTime:$screenTime}]-(:Actor {name:$actorName1})
194-
CREATE (m)<-[:ACTED_IN {screenTime:$screenTime}]-(:Actor {name:$actorName2})
180+
CREATE (m:${Movie} {id: $movieId})
181+
CREATE (m)<-[:ACTED_IN {screenTime:$screenTime}]-(:${Actor} {name:$actorName1})
182+
CREATE (m)<-[:ACTED_IN {screenTime:$screenTime}]-(:${Actor} {name:$actorName2})
195183
`,
196184
{ movieId, screenTime, actorName1, actorName2 }
197185
);
@@ -205,8 +193,8 @@ describe("composite-where", () => {
205193

206194
expect(gqlResult.errors).toBeFalsy();
207195

208-
expect(gqlResult?.data?.updateMovies).toEqual({
209-
movies: [{ id: movieId, actors: [{ name: actorName2 }] }],
196+
expect(gqlResult?.data?.[Movie.operations.update]).toEqual({
197+
[Movie.plural]: [{ id: movieId, actors: [{ name: actorName2 }] }],
210198
});
211199
} finally {
212200
await session.close();

packages/graphql/tests/integration/config-options/query-options.int.test.ts

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,53 +17,59 @@
1717
* limitations under the License.
1818
*/
1919

20-
import type { Driver } from "neo4j-driver";
2120
import { graphql } from "graphql";
21+
import type { Driver } from "neo4j-driver";
2222
import { generate } from "randomstring";
23-
import Neo4jHelper from "../neo4j";
2423
import { Neo4jGraphQL } from "../../../src/classes";
24+
import { UniqueType } from "../../utils/graphql-types";
25+
import Neo4jHelper from "../neo4j";
2526

2627
describe("query options", () => {
2728
let driver: Driver;
2829
let neo4j: Neo4jHelper;
30+
let neoSchema: Neo4jGraphQL;
31+
32+
let Actor: UniqueType;
33+
let Movie: UniqueType;
2934

3035
beforeAll(async () => {
3136
neo4j = new Neo4jHelper();
3237
driver = await neo4j.getDriver();
33-
});
34-
35-
afterAll(async () => {
36-
await driver.close();
37-
});
38-
39-
test("queries should work with runtime set to interpreted", async () => {
40-
const session = await neo4j.getSession();
41-
38+
Actor = new UniqueType("Actor");
39+
Movie = new UniqueType("Movie");
4240
const typeDefs = `
43-
type Actor {
41+
type ${Actor} {
4442
name: String
45-
movies: [Movie!]! @relationship(type: "ACTED_IN", direction: IN)
43+
movies: [${Movie}!]! @relationship(type: "ACTED_IN", direction: IN)
4644
}
47-
48-
type Movie {
45+
46+
type ${Movie} {
4947
id: ID!
5048
title: String!
51-
actors: [Actor!]! @relationship(type: "ACTED_IN", direction: OUT)
49+
actors: [${Actor}!]! @relationship(type: "ACTED_IN", direction: OUT)
5250
}
5351
`;
5452

55-
const neoSchema = new Neo4jGraphQL({
53+
neoSchema = new Neo4jGraphQL({
5654
typeDefs,
5755
driver,
5856
});
57+
});
58+
59+
afterAll(async () => {
60+
await driver.close();
61+
});
62+
63+
test("queries should work with runtime set to interpreted", async () => {
64+
const session = await neo4j.getSession();
5965

6066
const id = generate({
6167
charset: "alphabetic",
6268
});
6369

6470
const query = `
6571
query($id: ID){
66-
movies(where: {id: $id}){
72+
${Movie.plural}(where: {id: $id}){
6773
id
6874
}
6975
}
@@ -74,7 +80,7 @@ describe("query options", () => {
7480

7581
await session.run(
7682
`
77-
CREATE (:Movie {id: $id}), (:Movie {id: $id}), (:Movie {id: $id})
83+
CREATE (:${Movie} {id: $id}), (:${Movie} {id: $id}), (:${Movie} {id: $id})
7884
`,
7985
{ id }
8086
);
@@ -88,7 +94,7 @@ describe("query options", () => {
8894

8995
expect(result.errors).toBeFalsy();
9096

91-
expect(result?.data?.movies).toEqual([{ id }, { id }, { id }]);
97+
expect(result?.data?.[Movie.plural]).toEqual([{ id }, { id }, { id }]);
9298
} finally {
9399
await session.close();
94100
}

0 commit comments

Comments
 (0)