Skip to content

Commit

Permalink
Merge pull request #5859 from mjfwebb/6x-cypher-relationship-filter-t…
Browse files Browse the repository at this point in the history
…ests-update

Cypher relationship filters tests use `_SOME`
  • Loading branch information
mjfwebb authored Nov 29, 2024
2 parents 8024a88 + ffcbc4a commit 56de1c7
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 326 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,96 +26,6 @@ describe("Connection API - cypher directive filtering - Relationship", () => {
await testHelper.close();
});

test("Connection API - relationship with single property filter", async () => {
const Movie = testHelper.createUniqueType("Movie");
const Actor = testHelper.createUniqueType("Actor");

const typeDefs = /* GraphQL */ `
type ${Movie} @node {
title: String
actors: [${Actor}!]!
@cypher(
statement: """
MATCH (this)<-[:ACTED_IN]-(actor:${Actor})
RETURN actor
"""
columnName: "actor"
)
}
type ${Actor} @node {
name: String
movies: [${Movie}!]!
@cypher(
statement: """
MATCH (this)-[:ACTED_IN]->(movie:${Movie})
RETURN movie
"""
columnName: "movie"
)
}
`;

await testHelper.initNeo4jGraphQL({ typeDefs });
await testHelper.executeCypher(
`
CREATE (m:${Movie} { title: "The Matrix" })
CREATE (m2:${Movie} { title: "The Matrix Reloaded" })
CREATE (m3:${Movie} { title: "The Matrix Revolutions" })
CREATE (a:${Actor} { name: "Keanu Reeves" })
CREATE (a)-[:ACTED_IN]->(m)
CREATE (a)-[:ACTED_IN]->(m2)
CREATE (a)-[:ACTED_IN]->(m3)
CREATE (a2:${Actor} { name: "Carrie-Anne Moss" })
CREATE (a2)-[:ACTED_IN]->(m)
CREATE (a2)-[:ACTED_IN]->(m2)
CREATE (a2)-[:ACTED_IN]->(m3)
CREATE (a3:${Actor} { name: "Jada Pinkett Smith" })
CREATE (a3)-[:ACTED_IN]->(m2)
CREATE (a3)-[:ACTED_IN]->(m3)
`,
{}
);

const query = /* GraphQL */ `
query {
${Movie.operations.connection}(
where: {
actors: {
name_EQ: "Jada Pinkett Smith"
}
}
) {
edges {
node {
title
}
}
}
}
`;

const gqlResult = await testHelper.executeGraphQL(query);

expect(gqlResult.errors).toBeFalsy();
expect(gqlResult?.data).toEqual({
[Movie.operations.connection]: {
edges: expect.toIncludeSameMembers([
{
node: {
title: "The Matrix Reloaded",
},
},
{
node: {
title: "The Matrix Revolutions",
},
},
]),
},
});
});

test("Connection API - relationship with single property filter NOT", async () => {
const Movie = testHelper.createUniqueType("Movie");
const Actor = testHelper.createUniqueType("Actor");
Expand Down Expand Up @@ -172,7 +82,7 @@ describe("Connection API - cypher directive filtering - Relationship", () => {
${Movie.operations.connection}(
where: {
NOT: {
actors: {
actors_SOME: {
name_EQ: "Jada Pinkett Smith"
}
}
Expand Down Expand Up @@ -689,8 +599,8 @@ describe("Connection API - cypher directive filtering - Relationship", () => {
${Movie.operations.connection}(
where: {
OR: [
{ actors: { name_EQ: "Jada Pinkett Smith" } },
{ genres: { name_EQ: "Romance" } }
{ actors_SOME: { name_EQ: "Jada Pinkett Smith" } },
{ genres_SOME: { name_EQ: "Romance" } }
]
}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,86 +26,6 @@ describe("cypher directive filtering - Relationship", () => {
await testHelper.close();
});

test("relationship with single property filter", async () => {
const Movie = testHelper.createUniqueType("Movie");
const Actor = testHelper.createUniqueType("Actor");

const typeDefs = /* GraphQL */ `
type ${Movie} @node {
title: String
actors: [${Actor}!]!
@cypher(
statement: """
MATCH (this)<-[:ACTED_IN]-(actor:${Actor})
RETURN actor
"""
columnName: "actor"
)
}
type ${Actor} @node {
name: String
movies: [${Movie}!]!
@cypher(
statement: """
MATCH (this)-[:ACTED_IN]->(movie:${Movie})
RETURN movie
"""
columnName: "movie"
)
}
`;

await testHelper.initNeo4jGraphQL({ typeDefs });
await testHelper.executeCypher(
`
CREATE (m:${Movie} { title: "The Matrix" })
CREATE (m2:${Movie} { title: "The Matrix Reloaded" })
CREATE (m3:${Movie} { title: "The Matrix Revolutions" })
CREATE (a:${Actor} { name: "Keanu Reeves" })
CREATE (a)-[:ACTED_IN]->(m)
CREATE (a)-[:ACTED_IN]->(m2)
CREATE (a)-[:ACTED_IN]->(m3)
CREATE (a2:${Actor} { name: "Carrie-Anne Moss" })
CREATE (a2)-[:ACTED_IN]->(m)
CREATE (a2)-[:ACTED_IN]->(m2)
CREATE (a2)-[:ACTED_IN]->(m3)
CREATE (a3:${Actor} { name: "Jada Pinkett Smith" })
CREATE (a3)-[:ACTED_IN]->(m2)
CREATE (a3)-[:ACTED_IN]->(m3)
`,
{}
);

const query = /* GraphQL */ `
query {
${Movie.plural}(
where: {
actors: {
name_EQ: "Jada Pinkett Smith"
}
}
) {
title
}
}
`;

const gqlResult = await testHelper.executeGraphQL(query);

expect(gqlResult.errors).toBeFalsy();
expect(gqlResult?.data).toEqual({
[Movie.plural]: expect.toIncludeSameMembers([
{
title: "The Matrix Reloaded",
},
{
title: "The Matrix Revolutions",
},
]),
});
});

test("relationship with single property filter NOT", async () => {
const Movie = testHelper.createUniqueType("Movie");
const Actor = testHelper.createUniqueType("Actor");
Expand Down Expand Up @@ -162,7 +82,7 @@ describe("cypher directive filtering - Relationship", () => {
${Movie.plural}(
where: {
NOT: {
actors: {
actors_SOME: {
name_EQ: "Jada Pinkett Smith"
}
}
Expand Down Expand Up @@ -553,8 +473,8 @@ describe("cypher directive filtering - Relationship", () => {
${Movie.plural}(
where: {
OR: [
{ actors: { name_EQ: "Jada Pinkett Smith" } },
{ genres: { name_EQ: "Romance" } }
{ actors_SOME: { name_EQ: "Jada Pinkett Smith" } },
{ genres_SOME: { name_EQ: "Romance" } }
]
}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe("cypher directive filtering - relationship auth filter", () => {
const typeDefs = /* GraphQL */ `
type Movie
@node
@authorization(filter: [{ where: { node: { actors: { name_EQ: "$jwt.custom_value" } } } }]) {
@authorization(filter: [{ where: { node: { actors_SOME: { name_EQ: "$jwt.custom_value" } } } }]) {
title: String
rating: Float
actors: [Actor!]!
Expand Down Expand Up @@ -118,7 +118,7 @@ describe("cypher directive filtering - relationship auth filter", () => {
const typeDefs = /* GraphQL */ `
type Movie
@node
@authorization(filter: [{ where: { node: { actors: { name_EQ: "$jwt.custom_value" } } } }]) {
@authorization(filter: [{ where: { node: { actors_SOME: { name_EQ: "$jwt.custom_value" } } } }]) {
title: String
rating: Float
actors: [Actor!]!
Expand Down Expand Up @@ -210,7 +210,7 @@ describe("cypher directive filtering - relationship auth filter", () => {
const typeDefs = /* GraphQL */ `
type Movie
@node
@authorization(validate: [{ where: { node: { actors: { name_EQ: "$jwt.custom_value" } } } }]) {
@authorization(validate: [{ where: { node: { actors_SOME: { name_EQ: "$jwt.custom_value" } } } }]) {
title: String
rating: Float
actors: [Actor!]!
Expand Down Expand Up @@ -302,7 +302,7 @@ describe("cypher directive filtering - relationship auth filter", () => {
const typeDefs = /* GraphQL */ `
type Movie
@node
@authorization(validate: [{ where: { node: { actors: { name_EQ: "$jwt.custom_value" } } } }]) {
@authorization(validate: [{ where: { node: { actors_SOME: { name_EQ: "$jwt.custom_value" } } } }]) {
title: String
rating: Float
actors: [Actor!]!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,83 +21,6 @@ import { Neo4jGraphQL } from "../../../../../../src";
import { formatCypher, formatParams, translateQuery } from "../../../../utils/tck-test-utils";

describe("Connection API - cypher directive filtering - Relationship", () => {
test("Connection API - relationship with single property filter", async () => {
const typeDefs = /* GraphQL */ `
type Movie @node {
title: String
actors: [Actor!]!
@cypher(
statement: """
MATCH (this)<-[:ACTED_IN]-(actor:Actor)
RETURN actor
"""
columnName: "actor"
)
}
type Actor @node {
name: String
movies: [Movie!]!
@cypher(
statement: """
MATCH (this)-[:ACTED_IN]->(movie:Movie)
RETURN movie
"""
columnName: "movie"
)
}
`;

const neoSchema: Neo4jGraphQL = new Neo4jGraphQL({
typeDefs,
});

const query = /* GraphQL */ `
query {
moviesConnection(where: { actors: { name_EQ: "Jada Pinkett Smith" } }) {
edges {
node {
title
}
}
}
}
`;

const result = await translateQuery(neoSchema, query);

expect(formatCypher(result.cypher)).toMatchInlineSnapshot(`
"MATCH (this0:Movie)
CALL {
WITH this0
CALL {
WITH this0
WITH this0 AS this
MATCH (this)<-[:ACTED_IN]-(actor:Actor)
RETURN actor
}
WITH actor AS this1
RETURN collect(this1) AS this2
}
WITH *
WHERE any(this3 IN this2 WHERE this3.name = $param0)
WITH collect({ node: this0 }) AS edges
WITH edges, size(edges) AS totalCount
CALL {
WITH edges
UNWIND edges AS edge
WITH edge.node AS this0
RETURN collect({ node: { title: this0.title, __resolveType: \\"Movie\\" } }) AS var4
}
RETURN { edges: var4, totalCount: totalCount } AS this"
`);
expect(formatParams(result.params)).toMatchInlineSnapshot(`
"{
\\"param0\\": \\"Jada Pinkett Smith\\"
}"
`);
});

test("Connection API - relationship with single property filter NOT", async () => {
const typeDefs = /* GraphQL */ `
type Movie @node {
Expand Down Expand Up @@ -131,7 +54,7 @@ describe("Connection API - cypher directive filtering - Relationship", () => {

const query = /* GraphQL */ `
query {
moviesConnection(where: { NOT: { actors: { name_EQ: "Jada Pinkett Smith" } } }) {
moviesConnection(where: { NOT: { actors_SOME: { name_EQ: "Jada Pinkett Smith" } } }) {
edges {
node {
title
Expand Down Expand Up @@ -616,7 +539,12 @@ describe("Connection API - cypher directive filtering - Relationship", () => {
const query = /* GraphQL */ `
query {
moviesConnection(
where: { OR: [{ actors: { name_EQ: "Jada Pinkett Smith" } }, { genres: { name_EQ: "Romance" } }] }
where: {
OR: [
{ actors_SOME: { name_EQ: "Jada Pinkett Smith" } }
{ genres_SOME: { name_EQ: "Romance" } }
]
}
) {
edges {
node {
Expand Down
Loading

0 comments on commit 56de1c7

Please sign in to comment.