Skip to content

Commit

Permalink
Add tests for nested delete with multiple types
Browse files Browse the repository at this point in the history
  • Loading branch information
angrykoala committed Oct 1, 2024
1 parent 33c1a98 commit 910ee92
Show file tree
Hide file tree
Showing 2 changed files with 132 additions and 2 deletions.
42 changes: 40 additions & 2 deletions packages/graphql/tests/integration/issues/5599.int.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describe("https://github.com/neo4j/graphql/issues/5599", () => {
let LeadActor: UniqueType;
let Extra: UniqueType;

beforeAll(async () => {
beforeEach(async () => {
Movie = testHelper.createUniqueType("Movie");
LeadActor = testHelper.createUniqueType("LeadActor");
Extra = testHelper.createUniqueType("Extra");
Expand Down Expand Up @@ -58,7 +58,7 @@ describe("https://github.com/neo4j/graphql/issues/5599", () => {
});
});

afterAll(async () => {
afterEach(async () => {
await testHelper.close();
});

Expand Down Expand Up @@ -99,4 +99,42 @@ describe("https://github.com/neo4j/graphql/issues/5599", () => {
},
});
});

test("update with nested delete of an union with multiple concrete entities", async () => {
await testHelper.executeCypher(`
CREATE(m:${Movie} { title: "The Matrix"})<-[:ACTED_IN]-(:${LeadActor} {name: "Actor1"})
CREATE(m)<-[:ACTED_IN]-(:${LeadActor} {name: "Actor2"})
CREATE(m)<-[:ACTED_IN]-(:${Extra} {name: "Actor2"})
`);

const query = /* GraphQL */ `
mutation UpdateMovies {
${Movie.operations.update}(
update: { actors: { ${LeadActor}: [{ delete: [{ where: { node: { name: "Actor1" } } }] }], ${Extra}: [{ delete: [{ where: { node: { name: "Actor2" } } }] }] } }
) {
${Movie.plural} {
title
}
}
}
`;

const token = createBearerToken(secret, { sub: "1234" });
const response = await testHelper.executeGraphQLWithToken(query, token);
const remainingLeadActors = await testHelper.executeCypher(`MATCH(m:${LeadActor}) RETURN m`);
const remainingExtras = await testHelper.executeCypher(`MATCH(m:${Extra}) RETURN m`);

expect(response.errors).toBeFalsy();
expect(remainingLeadActors.records).toHaveLength(1);
expect(remainingExtras.records).toHaveLength(0);
expect(response.data).toEqual({
[Movie.operations.update]: {
[Movie.plural]: [
{
title: "The Matrix",
},
],
},
});
});
});
92 changes: 92 additions & 0 deletions packages/graphql/tests/tck/issues/5599.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,96 @@ describe("https://github.com/neo4j/graphql/issues/5599", () => {
}"
`);
});

test("update with nested delete of an union with multiple concrete entities", async () => {
const query = /* GraphQL */ `
mutation {
updateMovies(
update: {
actors: {
LeadActor: [{ delete: [{ where: { node: { name: "Actor1" } } }] }]
Extra: [{ delete: [{ where: { node: { name: "Actor2" } } }] }]
}
}
) {
movies {
title
}
}
}
`;

const result = await translateQuery(neoSchema, query);

expect(formatCypher(result.cypher)).toMatchInlineSnapshot(`
"MATCH (this:Movie)
WITH *
CALL {
WITH *
OPTIONAL MATCH (this)<-[this_actors_LeadActor0_delete0_relationship:ACTED_IN]-(this_actors_LeadActor0_delete0:LeadActor)
WHERE this_actors_LeadActor0_delete0.name = $updateMovies_args_update_actors0_delete_LeadActor0_where_this_actors_LeadActor0_delete0param0
WITH this_actors_LeadActor0_delete0_relationship, collect(DISTINCT this_actors_LeadActor0_delete0) AS this_actors_LeadActor0_delete0_to_delete
CALL {
WITH this_actors_LeadActor0_delete0_to_delete
UNWIND this_actors_LeadActor0_delete0_to_delete AS x
DETACH DELETE x
}
}
WITH *
CALL {
WITH *
OPTIONAL MATCH (this)<-[this_actors_Extra0_delete0_relationship:ACTED_IN]-(this_actors_Extra0_delete0:Extra)
WHERE this_actors_Extra0_delete0.name = $updateMovies_args_update_actors0_delete_Extra0_where_this_actors_Extra0_delete0param0
WITH this_actors_Extra0_delete0_relationship, collect(DISTINCT this_actors_Extra0_delete0) AS this_actors_Extra0_delete0_to_delete
CALL {
WITH this_actors_Extra0_delete0_to_delete
UNWIND this_actors_Extra0_delete0_to_delete AS x
DETACH DELETE x
}
}
RETURN collect(DISTINCT this { .title }) AS data"
`);

expect(formatParams(result.params)).toMatchInlineSnapshot(`
"{
\\"updateMovies_args_update_actors0_delete_LeadActor0_where_this_actors_LeadActor0_delete0param0\\": \\"Actor1\\",
\\"updateMovies_args_update_actors0_delete_Extra0_where_this_actors_Extra0_delete0param0\\": \\"Actor2\\",
\\"updateMovies\\": {
\\"args\\": {
\\"update\\": {
\\"actors\\": {
\\"LeadActor\\": [
{
\\"delete\\": [
{
\\"where\\": {
\\"node\\": {
\\"name\\": \\"Actor1\\"
}
}
}
]
}
],
\\"Extra\\": [
{
\\"delete\\": [
{
\\"where\\": {
\\"node\\": {
\\"name\\": \\"Actor2\\"
}
}
}
]
}
]
}
}
}
},
\\"resolvedCallbacks\\": {}
}"
`);
});
});

0 comments on commit 910ee92

Please sign in to comment.