-
Notifications
You must be signed in to change notification settings - Fork 152
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix Cypher when filtering by aggregations over different relationship…
… properties types (#5943) * Fix Cypher when filtering by aggregations over different relationship properites types * Update friendly-pigs-wait.md * Fix issues * Add small explanation * Fix edge case
- Loading branch information
1 parent
fd3f015
commit 6153d68
Showing
5 changed files
with
472 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@neo4j/graphql": patch | ||
--- | ||
|
||
Fix Cypher when filtering by aggregations over different relationship properties types |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
156 changes: 156 additions & 0 deletions
156
packages/graphql/tests/integration/aggregations/where/edge/interfaces.int.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,156 @@ | ||
import type { UniqueType } from "../../../../utils/graphql-types"; | ||
import { TestHelper } from "../../../../utils/tests-helper"; | ||
|
||
describe("aggregations-where-edge-string interface relationships of interface types", () => { | ||
let testHelper: TestHelper; | ||
|
||
let Movie: UniqueType; | ||
let Series: UniqueType; | ||
let Production: UniqueType; | ||
let Actor: UniqueType; | ||
let Cameo: UniqueType; | ||
let Person: UniqueType; | ||
|
||
beforeEach(async () => { | ||
testHelper = new TestHelper(); | ||
|
||
Movie = testHelper.createUniqueType("Movie"); | ||
Series = testHelper.createUniqueType("Series"); | ||
Production = testHelper.createUniqueType("Production"); | ||
Actor = testHelper.createUniqueType("Actor"); | ||
Cameo = testHelper.createUniqueType("Cameo"); | ||
Person = testHelper.createUniqueType("Person"); | ||
|
||
const typeDefs = /* GraphQL */ ` | ||
interface ${Production} { | ||
title: String | ||
} | ||
type ${Movie} implements ${Production} @node { | ||
title: String | ||
} | ||
type ${Series} implements ${Production} @node { | ||
title: String | ||
} | ||
interface ${Person} { | ||
name: String | ||
productions: [${Production}!]! @declareRelationship | ||
} | ||
type ${Actor} implements ${Person} @node { | ||
name: String | ||
productions: [${Production}!]! @relationship(type: "ACTED_IN", direction: OUT, properties: "ActedIn") | ||
} | ||
type ${Cameo} implements ${Person} @node { | ||
name: String | ||
productions: [${Production}!]! @relationship(type: "APPEARED_IN", direction: OUT, properties: "AppearedIn") | ||
} | ||
type ActedIn @relationshipProperties { | ||
role: String | ||
} | ||
type AppearedIn @relationshipProperties { | ||
role: String | ||
} | ||
`; | ||
|
||
await testHelper.initNeo4jGraphQL({ typeDefs }); | ||
}); | ||
|
||
afterEach(async () => { | ||
await testHelper.close(); | ||
}); | ||
|
||
test("should return nodes aggregated across different relationship properties types", async () => { | ||
await testHelper.executeCypher( | ||
` | ||
CREATE (a:${Actor} { name: "A" })-[:ACTED_IN { role: "definitely too long" }]->(g:${Movie} { title: "G" }) | ||
CREATE (a)-[:ACTED_IN { role: "extremely long" }]->(g) | ||
CREATE (b:${Actor} { name: "B" })-[:ACTED_IN { role: "a" }]->(h:${Series} { title: "H" }) | ||
CREATE (b)-[:ACTED_IN { role: "b" }]->(h) | ||
CREATE (c:${Actor} { name: "C" }) | ||
CREATE (d:${Cameo} { name: "D" })-[:APPEARED_IN { role: "too long" }]->(i:${Movie} { title: "I" }) | ||
CREATE (d)-[:APPEARED_IN { role: "also too long" }]->(i) | ||
CREATE (e:${Cameo} { name: "E" })-[:APPEARED_IN { role: "s" }]->(j:${Series} { title: "J" }) | ||
CREATE (e)-[:APPEARED_IN { role: "very long" }]->(j) | ||
CREATE (f:${Cameo} { name: "F" }) | ||
` | ||
); | ||
|
||
const query = /* GraphQL */ ` | ||
query People { | ||
${Person.plural}( | ||
where: { | ||
productionsAggregate: { | ||
edge: { | ||
AppearedIn: { role_SHORTEST_LENGTH_LT: 3 } | ||
ActedIn: { role_AVERAGE_LENGTH_LT: 5 } | ||
} | ||
} | ||
} | ||
) { | ||
name | ||
} | ||
} | ||
`; | ||
|
||
const gqlResult = await testHelper.executeGraphQL(query); | ||
|
||
if (gqlResult.errors) { | ||
console.log(JSON.stringify(gqlResult.errors, null, 2)); | ||
} | ||
|
||
expect(gqlResult.errors).toBeUndefined(); | ||
|
||
expect((gqlResult.data as any)[Person.plural]).toIncludeSameMembers([{ name: "E" }, { name: "B" }]); | ||
}); | ||
|
||
test("should return nodes aggregated across relationship properties and count", async () => { | ||
await testHelper.executeCypher( | ||
` | ||
CREATE (a:${Actor} { name: "A" })-[:ACTED_IN { role: "definitely too long" }]->(g:${Movie} { title: "G" }) | ||
CREATE (a)-[:ACTED_IN { role: "extremely long" }]->(g) | ||
CREATE (b:${Actor} { name: "B" })-[:ACTED_IN { role: "a" }]->(h:${Series} { title: "H" }) | ||
CREATE (b)-[:ACTED_IN { role: "b" }]->(h) | ||
CREATE (b2:${Actor} { name: "B2" })-[:ACTED_IN { role: "a" }]->(h2:${Series} { title: "H2" }) | ||
CREATE (b2)-[:ACTED_IN { role: "b" }]->(h2) | ||
CREATE (b2)-[:ACTED_IN { role: "b" }]->(h2) | ||
CREATE (c:${Actor} { name: "C" }) | ||
CREATE (d:${Cameo} { name: "D" })-[:APPEARED_IN { role: "too long" }]->(i:${Movie} { title: "I" }) | ||
CREATE (d)-[:APPEARED_IN { role: "also too long" }]->(i) | ||
CREATE (e:${Cameo} { name: "E" })-[:APPEARED_IN { role: "s" }]->(j:${Series} { title: "J" }) | ||
CREATE (e)-[:APPEARED_IN { role: "very long" }]->(j) | ||
CREATE (e)-[:APPEARED_IN { role: "another very long" }]->(j) | ||
CREATE (f:${Cameo} { name: "F" }) | ||
` | ||
); | ||
|
||
const query = /* GraphQL */ ` | ||
query People { | ||
${Person.plural}( | ||
where: { productionsAggregate: { edge: { ActedIn: { role_AVERAGE_LENGTH_LT: 5 } }, count_LT: 3 } } | ||
) { | ||
name | ||
} | ||
} | ||
`; | ||
|
||
const gqlResult = await testHelper.executeGraphQL(query); | ||
|
||
if (gqlResult.errors) { | ||
console.log(JSON.stringify(gqlResult.errors, null, 2)); | ||
} | ||
|
||
expect(gqlResult.errors).toBeUndefined(); | ||
|
||
expect((gqlResult.data as any)[Person.plural]).toIncludeSameMembers([ | ||
{ name: "D" }, | ||
{ name: "B" }, | ||
{ name: "F" }, | ||
]); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.