Skip to content

Commit 44c6f7c

Browse files
Merge pull request #4860 from MacondoExpress/unique-type-chunk-ic
Update integration tests on interface-relationship path to use UniqueType
2 parents 089e587 + 66a4617 commit 44c6f7c

File tree

8 files changed

+296
-200
lines changed

8 files changed

+296
-200
lines changed

packages/graphql/tests/integration/interface-relationships/create/connect.int.test.ts

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,49 +19,59 @@
1919

2020
import { faker } from "@faker-js/faker";
2121
import { graphql } from "graphql";
22-
import { gql } from "graphql-tag";
2322
import type { Driver } from "neo4j-driver";
2423
import { generate } from "randomstring";
2524
import { Neo4jGraphQL } from "../../../../src/classes";
25+
import { cleanNodesUsingSession } from "../../../utils/clean-nodes";
26+
import { UniqueType } from "../../../utils/graphql-types";
2627
import Neo4jHelper from "../../neo4j";
2728

2829
describe("interface relationships", () => {
2930
let driver: Driver;
3031
let neo4j: Neo4jHelper;
3132
let neoSchema: Neo4jGraphQL;
33+
let Episode: UniqueType;
34+
let Actor: UniqueType;
35+
let Movie: UniqueType;
36+
let Series: UniqueType;
3237

3338
beforeAll(async () => {
3439
neo4j = new Neo4jHelper();
3540
driver = await neo4j.getDriver();
3641

37-
const typeDefs = gql`
38-
type Episode {
42+
Episode = new UniqueType("Episode");
43+
Actor = new UniqueType("Actor");
44+
Movie = new UniqueType("Movie");
45+
Series = new UniqueType("Series");
46+
47+
const typeDefs = /* GraphQL */ `
48+
type ${Episode} {
3949
runtime: Int!
40-
series: Series! @relationship(type: "HAS_EPISODE", direction: IN)
50+
series: ${Series}! @relationship(type: "HAS_EPISODE", direction: IN)
4151
}
4252
4353
interface Production {
4454
title: String!
45-
actors: [Actor!]! @declareRelationship
55+
actors: [${Actor}!]! @declareRelationship
4656
}
4757
48-
type Movie implements Production {
58+
type ${Movie} implements Production {
4959
title: String!
5060
runtime: Int!
51-
actors: [Actor!]! @relationship(type: "ACTED_IN", direction: IN, properties: "ActedIn")
61+
actors: [${Actor}!]! @relationship(type: "ACTED_IN", direction: IN, properties: "ActedIn")
5262
}
5363
54-
type Series implements Production {
64+
type ${Series} implements Production {
5565
title: String!
56-
episodes: [Episode!]! @relationship(type: "HAS_EPISODE", direction: OUT)
57-
actors: [Actor!]! @relationship(type: "ACTED_IN", direction: IN, properties: "ActedIn")
66+
episodes: [${Episode}!]! @relationship(type: "HAS_EPISODE", direction: OUT)
67+
actors: [${Actor}!]! @relationship(type: "ACTED_IN", direction: IN, properties: "ActedIn")
5868
}
5969
6070
type ActedIn @relationshipProperties {
6171
screenTime: Int!
6272
}
6373
64-
type Actor {
74+
type ${Actor} {
6575
name: String!
6676
actedIn: [Production!]! @relationship(type: "ACTED_IN", direction: OUT, properties: "ActedIn")
6777
}
@@ -73,6 +83,8 @@ describe("interface relationships", () => {
7383
});
7484

7585
afterAll(async () => {
86+
const session = await neo4j.getSession();
87+
await cleanNodesUsingSession(session, [Actor, Movie, Series, Episode]);
7688
await driver.close();
7789
});
7890

@@ -97,7 +109,7 @@ describe("interface relationships", () => {
97109

98110
const query = `
99111
mutation CreateActorConnectMovie($name1: String!, $title: String, $screenTime: Int!, $name2: String) {
100-
createActors(
112+
${Actor.operations.create}(
101113
input: [
102114
{
103115
name: $name1
@@ -113,14 +125,14 @@ describe("interface relationships", () => {
113125
}
114126
]
115127
) {
116-
actors {
128+
${Actor.plural} {
117129
name
118130
actedIn {
119131
title
120132
actors {
121133
name
122134
}
123-
... on Movie {
135+
... on ${Movie} {
124136
runtime
125137
}
126138
}
@@ -132,8 +144,8 @@ describe("interface relationships", () => {
132144
try {
133145
await session.run(
134146
`
135-
CREATE (:Movie { title: $movieTitle, runtime:$movieRuntime })
136-
CREATE (:Actor { name: $name })
147+
CREATE (:${Movie} { title: $movieTitle, runtime:$movieRuntime })
148+
CREATE (:${Actor} { name: $name })
137149
`,
138150
{ movieTitle, movieRuntime, name: actorName2 }
139151
);
@@ -153,8 +165,8 @@ describe("interface relationships", () => {
153165
expect(gqlResult.errors).toBeFalsy();
154166

155167
expect(gqlResult.data).toEqual({
156-
createActors: {
157-
actors: [
168+
[Actor.operations.create]: {
169+
[Actor.plural]: [
158170
{
159171
actedIn: [
160172
{

packages/graphql/tests/integration/interface-relationships/create/create.int.test.ts

Lines changed: 37 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -19,49 +19,59 @@
1919

2020
import { faker } from "@faker-js/faker";
2121
import { graphql } from "graphql";
22-
import { gql } from "graphql-tag";
2322
import type { Driver } from "neo4j-driver";
2423
import { generate } from "randomstring";
2524
import { Neo4jGraphQL } from "../../../../src/classes";
25+
import { cleanNodesUsingSession } from "../../../utils/clean-nodes";
26+
import { UniqueType } from "../../../utils/graphql-types";
2627
import Neo4jHelper from "../../neo4j";
2728

2829
describe("interface relationships", () => {
2930
let driver: Driver;
3031
let neo4j: Neo4jHelper;
3132
let neoSchema: Neo4jGraphQL;
33+
let Episode: UniqueType;
34+
let Actor: UniqueType;
35+
let Movie: UniqueType;
36+
let Series: UniqueType;
3237

3338
beforeAll(async () => {
3439
neo4j = new Neo4jHelper();
3540
driver = await neo4j.getDriver();
3641

37-
const typeDefs = gql`
38-
type Episode {
42+
Episode = new UniqueType("Episode");
43+
Actor = new UniqueType("Actor");
44+
Movie = new UniqueType("Movie");
45+
Series = new UniqueType("Series");
46+
47+
const typeDefs = /* GraphQL */ `
48+
type ${Episode} {
3949
runtime: Int!
40-
series: Series! @relationship(type: "HAS_EPISODE", direction: IN)
50+
series: ${Series}! @relationship(type: "HAS_EPISODE", direction: IN)
4151
}
4252
4353
interface Production {
4454
title: String!
45-
actors: [Actor!]! @declareRelationship
55+
actors: [${Actor}!]! @declareRelationship
4656
}
4757
48-
type Movie implements Production {
58+
type ${Movie} implements Production {
4959
title: String!
5060
runtime: Int!
51-
actors: [Actor!]! @relationship(type: "ACTED_IN", direction: IN, properties: "ActedIn")
61+
actors: [${Actor}!]! @relationship(type: "ACTED_IN", direction: IN, properties: "ActedIn")
5262
}
5363
54-
type Series implements Production {
64+
type ${Series} implements Production {
5565
title: String!
56-
episodes: [Episode!]! @relationship(type: "HAS_EPISODE", direction: OUT)
57-
actors: [Actor!]! @relationship(type: "ACTED_IN", direction: IN, properties: "ActedIn")
66+
episodes: [${Episode}!]! @relationship(type: "HAS_EPISODE", direction: OUT)
67+
actors: [${Actor}!]! @relationship(type: "ACTED_IN", direction: IN, properties: "ActedIn")
5868
}
5969
6070
type ActedIn @relationshipProperties {
6171
screenTime: Int!
6272
}
6373
64-
type Actor {
74+
type ${Actor} {
6575
name: String!
6676
actedIn: [Production!]! @relationship(type: "ACTED_IN", direction: OUT, properties: "ActedIn")
6777
}
@@ -73,6 +83,8 @@ describe("interface relationships", () => {
7383
});
7484

7585
afterAll(async () => {
86+
const session = await neo4j.getSession();
87+
await cleanNodesUsingSession(session, [Actor, Movie, Series, Episode]);
7688
await driver.close();
7789
});
7890

@@ -93,24 +105,24 @@ describe("interface relationships", () => {
93105

94106
const query = `
95107
mutation CreateActorConnectMovie($name: String!, $title: String!, $runtime: Int!, $screenTime: Int!) {
96-
createActors(
108+
${Actor.operations.create}(
97109
input: [
98110
{
99111
name: $name
100112
actedIn: {
101113
create: {
102114
edge: { screenTime: $screenTime }
103-
node: { Movie: { title: $title, runtime: $runtime } }
115+
node: { ${Movie}: { title: $title, runtime: $runtime } }
104116
}
105117
}
106118
}
107119
]
108120
) {
109-
actors {
121+
${Actor.plural} {
110122
name
111123
actedIn {
112124
title
113-
... on Movie {
125+
... on ${Movie} {
114126
runtime
115127
}
116128
}
@@ -135,8 +147,8 @@ describe("interface relationships", () => {
135147
expect(gqlResult.errors).toBeFalsy();
136148

137149
expect(gqlResult.data).toEqual({
138-
createActors: {
139-
actors: [
150+
[Actor.operations.create]: {
151+
[Actor.plural]: [
140152
{
141153
actedIn: [
142154
{
@@ -190,7 +202,7 @@ describe("interface relationships", () => {
190202
$seriesTitle: String!
191203
$episodeRuntime: Int!
192204
) {
193-
createActors(
205+
${Actor.operations.create}(
194206
input: [
195207
{
196208
name: $name1
@@ -199,7 +211,7 @@ describe("interface relationships", () => {
199211
{
200212
edge: { screenTime: $screenTime }
201213
node: {
202-
Movie: {
214+
${Movie}: {
203215
title: $movieTitle
204216
runtime: $movieRuntime
205217
actors: {
@@ -214,7 +226,7 @@ describe("interface relationships", () => {
214226
{
215227
edge: { screenTime: $screenTime }
216228
node: {
217-
Series: {
229+
${Series}: {
218230
title: $seriesTitle
219231
episodes: { create: { node: { runtime: $episodeRuntime } } }
220232
}
@@ -225,17 +237,17 @@ describe("interface relationships", () => {
225237
}
226238
]
227239
) {
228-
actors {
240+
${Actor.plural} {
229241
name
230242
actedIn {
231243
title
232244
actors {
233245
name
234246
}
235-
... on Movie {
247+
... on ${Movie} {
236248
runtime
237249
}
238-
... on Series {
250+
... on ${Series} {
239251
episodes {
240252
runtime
241253
}
@@ -265,8 +277,8 @@ describe("interface relationships", () => {
265277
expect(gqlResult.errors).toBeFalsy();
266278

267279
expect(gqlResult.data).toEqual({
268-
createActors: {
269-
actors: [
280+
[Actor.operations.create]: {
281+
[Actor.plural]: [
270282
{
271283
actedIn: expect.toIncludeSameMembers([
272284
{

0 commit comments

Comments
 (0)