Skip to content

Commit 15ac500

Browse files
AakashSorathiyaaakash.sorathiya
andauthored
change filter generation logic for types whose parent is type relation (#272)
Co-authored-by: aakash.sorathiya <aakash.sorathiya@infosys.com>
1 parent f37f1de commit 15ac500

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,14 @@ open class ProjectionBase(
178178
if (value !is Map<*, *>) {
179179
throw IllegalArgumentException("Only object values are supported for filtering on queried relation ${predicate.value}, but got ${value.javaClass.name}")
180180
}
181+
if(type.isRelationType()) {
182+
val targetNode = predicate.relNode.named(normalizeName(propertyContainer.requiredSymbolicName.value, predicate.relationshipInfo.typeName))
183+
val relType = predicate.relationshipInfo.type
184+
val parsedQuery2 = parseFilter(value, relType)
185+
val condition = handleQuery(targetNode.requiredSymbolicName.value, "", targetNode, parsedQuery2, relType, variables)
186+
result = result.and(condition)
187+
continue
188+
}
181189

182190
val cond = name(normalizeName(variablePrefix, predicate.relationshipInfo.typeName, "Cond"))
183191
when (predicate.op) {

core/src/test/resources/filter-tests.adoc

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,24 @@ type Person {
1515
fun: Boolean
1616
gender: Gender
1717
company: Company @relation(name:"WORKS_AT")
18+
skills: [PersonSkills]
1819
location: _Neo4jPoint
1920
}
2021
type Company {
2122
_id: ID
2223
name: String
2324
employees: [Person] @relation(name:"WORKS_AT", direction: IN)
2425
}
26+
type Skill {
27+
id: ID!
28+
name: String
29+
skilledPerson: [Person] @relation(name: "HAS_SKILL", direction: OUT)
30+
}
31+
type PersonSkills @relation(name: "HAS_SKILL", from: "person", to: "skill") {
32+
person: Person
33+
skill: Skill
34+
proficiencyLevel: Int
35+
}
2536
----
2637

2738
== Test Data
@@ -3261,6 +3272,44 @@ RETURN p {
32613272

32623273
'''
32633274

3275+
=== Filter object whose parent is relationship
3276+
3277+
.GraphQL-Query
3278+
[source,graphql]
3279+
----
3280+
{ person { skills(filter: {skill: {name_starts_with: "F"}}) { skill { name } proficiencyLevel }}}
3281+
----
3282+
3283+
.Cypher Params
3284+
[source,json]
3285+
----
3286+
{
3287+
"personSkillsSkillNameStartsWith" : "F"
3288+
}
3289+
----
3290+
3291+
.Cypher
3292+
[source,cypher]
3293+
----
3294+
MATCH (person:Person)
3295+
CALL {
3296+
WITH person
3297+
MATCH (person)-[personSkills:HAS_SKILL]->(personSkillsSkill:Skill)
3298+
WHERE personSkillsSkill.name STARTS WITH $personSkillsSkillNameStartsWith
3299+
RETURN collect(personSkills {
3300+
skill: personSkillsSkill {
3301+
.name
3302+
},
3303+
.proficiencyLevel
3304+
}) AS personSkills
3305+
}
3306+
RETURN person {
3307+
skills: personSkills
3308+
} AS person
3309+
----
3310+
3311+
'''
3312+
32643313
=== Cascaded filter object string _eq_
32653314

32663315
.GraphQL-Query

0 commit comments

Comments
 (0)