Skip to content

Commit 2cc2ccd

Browse files
authored
Fix wrong node name used for projection where on relation (#301)
This bugfix fixes an issue where the name of the end-node of a relation is not correctly used in the where clause resolves #295
1 parent dbeeeba commit 2cc2ccd

File tree

2 files changed

+88
-2
lines changed

2 files changed

+88
-2
lines changed

core/src/main/kotlin/org/neo4j/graphql/handler/projection/ProjectionBase.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ open class ProjectionBase(
179179
throw IllegalArgumentException("Only object values are supported for filtering on queried relation ${predicate.value}, but got ${value.javaClass.name}")
180180
}
181181
if(type.isRelationType()) {
182-
val targetNode = predicate.relNode.named(normalizeName(propertyContainer.requiredSymbolicName.value, predicate.relationshipInfo.typeName))
182+
val targetNode = predicate.relNode.named(normalizeName(propertyContainer.requiredSymbolicName.value, predicate.relationshipInfo.endField.capitalize()))
183183
val relType = predicate.relationshipInfo.type
184184
val parsedQuery2 = parseFilter(value, relType)
185185
val condition = handleQuery(targetNode.requiredSymbolicName.value, "", targetNode, parsedQuery2, relType, variables)
@@ -552,7 +552,7 @@ open class ProjectionBase(
552552
else -> node(nodeType.name).named(childVariableName) to null
553553
}
554554

555-
val (projectionEntries, sub) = projectFields(endNodePattern, nodeType, env, name(childVariable), variableSuffix, field.selectionSet)
555+
val (projectionEntries, sub) = projectFields(endNodePattern, nodeType, env, childVariableName, variableSuffix, field.selectionSet)
556556

557557
val withPassThrough = mutableListOf(endNodePattern.requiredSymbolicName)
558558
var relationship = relInfo.createRelation(anyNode(variable), endNodePattern)
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
:toc:
2+
3+
= GitHub Issue #295: Wrong node name used for end node in rich relationship
4+
5+
== Schema
6+
7+
[source,graphql,schema=true]
8+
----
9+
type Person{
10+
name: String
11+
age: Int
12+
rel_has_target_book: [Person_HAS_Target_Book]
13+
}
14+
15+
type Book{
16+
name: String
17+
price: Int
18+
}
19+
20+
type Person_HAS_Target_Book @relation(name: "HAS", from: "source", to: "target", direction: OUT) {
21+
name: String
22+
source: Person
23+
target: Book
24+
}
25+
----
26+
27+
== Configuration
28+
29+
.Configuration
30+
[source,json,schema-config=true]
31+
----
32+
{
33+
"queryOptionStyle": "INPUT_TYPE",
34+
"useWhereFilter": true
35+
}
36+
----
37+
38+
== Query
39+
40+
.GraphQL-Query
41+
[source,graphql]
42+
----
43+
query{
44+
person{
45+
name
46+
rel_has_target_book(where:{name: "Foo", target:{name:"Book 1"}}){
47+
target{
48+
name
49+
}
50+
}
51+
}
52+
}
53+
----
54+
55+
.Cypher Params
56+
[source,json]
57+
----
58+
{
59+
"personRel_has_target_bookTargetName" : "Book 1",
60+
"wherePersonRel_has_target_bookName" : "Foo"
61+
}
62+
----
63+
64+
.Cypher
65+
[source,cypher]
66+
----
67+
MATCH (person:Person)
68+
CALL {
69+
WITH person
70+
MATCH (person)-[personRel_has_target_book:HAS]->(personRel_has_target_bookTarget:Book)
71+
WHERE (personRel_has_target_book.name = $wherePersonRel_has_target_bookName
72+
AND personRel_has_target_bookTarget.name = $personRel_has_target_bookTargetName)
73+
RETURN collect(personRel_has_target_book {
74+
target: personRel_has_target_bookTarget {
75+
.name
76+
}
77+
}) AS personRel_has_target_book
78+
}
79+
RETURN person {
80+
.name,
81+
rel_has_target_book: personRel_has_target_book
82+
} AS person
83+
----
84+
85+
'''
86+

0 commit comments

Comments
 (0)