Skip to content

Commit

Permalink
Merge pull request #4860 from MacondoExpress/unique-type-chunk-ic
Browse files Browse the repository at this point in the history
Update integration tests on interface-relationship path to use UniqueType
  • Loading branch information
MacondoExpress authored Mar 13, 2024
2 parents 089e587 + 66a4617 commit 44c6f7c
Show file tree
Hide file tree
Showing 8 changed files with 296 additions and 200 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,49 +19,59 @@

import { faker } from "@faker-js/faker";
import { graphql } from "graphql";
import { gql } from "graphql-tag";
import type { Driver } from "neo4j-driver";
import { generate } from "randomstring";
import { Neo4jGraphQL } from "../../../../src/classes";
import { cleanNodesUsingSession } from "../../../utils/clean-nodes";
import { UniqueType } from "../../../utils/graphql-types";
import Neo4jHelper from "../../neo4j";

describe("interface relationships", () => {
let driver: Driver;
let neo4j: Neo4jHelper;
let neoSchema: Neo4jGraphQL;
let Episode: UniqueType;
let Actor: UniqueType;
let Movie: UniqueType;
let Series: UniqueType;

beforeAll(async () => {
neo4j = new Neo4jHelper();
driver = await neo4j.getDriver();

const typeDefs = gql`
type Episode {
Episode = new UniqueType("Episode");
Actor = new UniqueType("Actor");
Movie = new UniqueType("Movie");
Series = new UniqueType("Series");

const typeDefs = /* GraphQL */ `
type ${Episode} {
runtime: Int!
series: Series! @relationship(type: "HAS_EPISODE", direction: IN)
series: ${Series}! @relationship(type: "HAS_EPISODE", direction: IN)
}
interface Production {
title: String!
actors: [Actor!]! @declareRelationship
actors: [${Actor}!]! @declareRelationship
}
type Movie implements Production {
type ${Movie} implements Production {
title: String!
runtime: Int!
actors: [Actor!]! @relationship(type: "ACTED_IN", direction: IN, properties: "ActedIn")
actors: [${Actor}!]! @relationship(type: "ACTED_IN", direction: IN, properties: "ActedIn")
}
type Series implements Production {
type ${Series} implements Production {
title: String!
episodes: [Episode!]! @relationship(type: "HAS_EPISODE", direction: OUT)
actors: [Actor!]! @relationship(type: "ACTED_IN", direction: IN, properties: "ActedIn")
episodes: [${Episode}!]! @relationship(type: "HAS_EPISODE", direction: OUT)
actors: [${Actor}!]! @relationship(type: "ACTED_IN", direction: IN, properties: "ActedIn")
}
type ActedIn @relationshipProperties {
screenTime: Int!
}
type Actor {
type ${Actor} {
name: String!
actedIn: [Production!]! @relationship(type: "ACTED_IN", direction: OUT, properties: "ActedIn")
}
Expand All @@ -73,6 +83,8 @@ describe("interface relationships", () => {
});

afterAll(async () => {
const session = await neo4j.getSession();
await cleanNodesUsingSession(session, [Actor, Movie, Series, Episode]);
await driver.close();
});

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

const query = `
mutation CreateActorConnectMovie($name1: String!, $title: String, $screenTime: Int!, $name2: String) {
createActors(
${Actor.operations.create}(
input: [
{
name: $name1
Expand All @@ -113,14 +125,14 @@ describe("interface relationships", () => {
}
]
) {
actors {
${Actor.plural} {
name
actedIn {
title
actors {
name
}
... on Movie {
... on ${Movie} {
runtime
}
}
Expand All @@ -132,8 +144,8 @@ describe("interface relationships", () => {
try {
await session.run(
`
CREATE (:Movie { title: $movieTitle, runtime:$movieRuntime })
CREATE (:Actor { name: $name })
CREATE (:${Movie} { title: $movieTitle, runtime:$movieRuntime })
CREATE (:${Actor} { name: $name })
`,
{ movieTitle, movieRuntime, name: actorName2 }
);
Expand All @@ -153,8 +165,8 @@ describe("interface relationships", () => {
expect(gqlResult.errors).toBeFalsy();

expect(gqlResult.data).toEqual({
createActors: {
actors: [
[Actor.operations.create]: {
[Actor.plural]: [
{
actedIn: [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,49 +19,59 @@

import { faker } from "@faker-js/faker";
import { graphql } from "graphql";
import { gql } from "graphql-tag";
import type { Driver } from "neo4j-driver";
import { generate } from "randomstring";
import { Neo4jGraphQL } from "../../../../src/classes";
import { cleanNodesUsingSession } from "../../../utils/clean-nodes";
import { UniqueType } from "../../../utils/graphql-types";
import Neo4jHelper from "../../neo4j";

describe("interface relationships", () => {
let driver: Driver;
let neo4j: Neo4jHelper;
let neoSchema: Neo4jGraphQL;
let Episode: UniqueType;
let Actor: UniqueType;
let Movie: UniqueType;
let Series: UniqueType;

beforeAll(async () => {
neo4j = new Neo4jHelper();
driver = await neo4j.getDriver();

const typeDefs = gql`
type Episode {
Episode = new UniqueType("Episode");
Actor = new UniqueType("Actor");
Movie = new UniqueType("Movie");
Series = new UniqueType("Series");

const typeDefs = /* GraphQL */ `
type ${Episode} {
runtime: Int!
series: Series! @relationship(type: "HAS_EPISODE", direction: IN)
series: ${Series}! @relationship(type: "HAS_EPISODE", direction: IN)
}
interface Production {
title: String!
actors: [Actor!]! @declareRelationship
actors: [${Actor}!]! @declareRelationship
}
type Movie implements Production {
type ${Movie} implements Production {
title: String!
runtime: Int!
actors: [Actor!]! @relationship(type: "ACTED_IN", direction: IN, properties: "ActedIn")
actors: [${Actor}!]! @relationship(type: "ACTED_IN", direction: IN, properties: "ActedIn")
}
type Series implements Production {
type ${Series} implements Production {
title: String!
episodes: [Episode!]! @relationship(type: "HAS_EPISODE", direction: OUT)
actors: [Actor!]! @relationship(type: "ACTED_IN", direction: IN, properties: "ActedIn")
episodes: [${Episode}!]! @relationship(type: "HAS_EPISODE", direction: OUT)
actors: [${Actor}!]! @relationship(type: "ACTED_IN", direction: IN, properties: "ActedIn")
}
type ActedIn @relationshipProperties {
screenTime: Int!
}
type Actor {
type ${Actor} {
name: String!
actedIn: [Production!]! @relationship(type: "ACTED_IN", direction: OUT, properties: "ActedIn")
}
Expand All @@ -73,6 +83,8 @@ describe("interface relationships", () => {
});

afterAll(async () => {
const session = await neo4j.getSession();
await cleanNodesUsingSession(session, [Actor, Movie, Series, Episode]);
await driver.close();
});

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

const query = `
mutation CreateActorConnectMovie($name: String!, $title: String!, $runtime: Int!, $screenTime: Int!) {
createActors(
${Actor.operations.create}(
input: [
{
name: $name
actedIn: {
create: {
edge: { screenTime: $screenTime }
node: { Movie: { title: $title, runtime: $runtime } }
node: { ${Movie}: { title: $title, runtime: $runtime } }
}
}
}
]
) {
actors {
${Actor.plural} {
name
actedIn {
title
... on Movie {
... on ${Movie} {
runtime
}
}
Expand All @@ -135,8 +147,8 @@ describe("interface relationships", () => {
expect(gqlResult.errors).toBeFalsy();

expect(gqlResult.data).toEqual({
createActors: {
actors: [
[Actor.operations.create]: {
[Actor.plural]: [
{
actedIn: [
{
Expand Down Expand Up @@ -190,7 +202,7 @@ describe("interface relationships", () => {
$seriesTitle: String!
$episodeRuntime: Int!
) {
createActors(
${Actor.operations.create}(
input: [
{
name: $name1
Expand All @@ -199,7 +211,7 @@ describe("interface relationships", () => {
{
edge: { screenTime: $screenTime }
node: {
Movie: {
${Movie}: {
title: $movieTitle
runtime: $movieRuntime
actors: {
Expand All @@ -214,7 +226,7 @@ describe("interface relationships", () => {
{
edge: { screenTime: $screenTime }
node: {
Series: {
${Series}: {
title: $seriesTitle
episodes: { create: { node: { runtime: $episodeRuntime } } }
}
Expand All @@ -225,17 +237,17 @@ describe("interface relationships", () => {
}
]
) {
actors {
${Actor.plural} {
name
actedIn {
title
actors {
name
}
... on Movie {
... on ${Movie} {
runtime
}
... on Series {
... on ${Series} {
episodes {
runtime
}
Expand Down Expand Up @@ -265,8 +277,8 @@ describe("interface relationships", () => {
expect(gqlResult.errors).toBeFalsy();

expect(gqlResult.data).toEqual({
createActors: {
actors: [
[Actor.operations.create]: {
[Actor.plural]: [
{
actedIn: expect.toIncludeSameMembers([
{
Expand Down
Loading

0 comments on commit 44c6f7c

Please sign in to comment.