Skip to content

change filter generation logic for types whose parent is type relation #272

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,14 @@ open class ProjectionBase(
if (value !is Map<*, *>) {
throw IllegalArgumentException("Only object values are supported for filtering on queried relation ${predicate.value}, but got ${value.javaClass.name}")
}
if(type.isRelationType()) {
val targetNode = predicate.relNode.named(normalizeName(propertyContainer.requiredSymbolicName.value, predicate.relationshipInfo.typeName))
val relType = predicate.relationshipInfo.type
val parsedQuery2 = parseFilter(value, relType)
val condition = handleQuery(targetNode.requiredSymbolicName.value, "", targetNode, parsedQuery2, relType, variables)
result = result.and(condition)
continue
}

val cond = name(normalizeName(variablePrefix, predicate.relationshipInfo.typeName, "Cond"))
when (predicate.op) {
Expand Down
49 changes: 49 additions & 0 deletions core/src/test/resources/filter-tests.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,24 @@ type Person {
fun: Boolean
gender: Gender
company: Company @relation(name:"WORKS_AT")
skills: [PersonSkills]
location: _Neo4jPoint
}
type Company {
_id: ID
name: String
employees: [Person] @relation(name:"WORKS_AT", direction: IN)
}
type Skill {
id: ID!
name: String
skilledPerson: [Person] @relation(name: "HAS_SKILL", direction: OUT)
}
type PersonSkills @relation(name: "HAS_SKILL", from: "person", to: "skill") {
person: Person
skill: Skill
proficiencyLevel: Int
}
----

== Test Data
Expand Down Expand Up @@ -3261,6 +3272,44 @@ RETURN p {

'''

=== Filter object whose parent is relationship

.GraphQL-Query
[source,graphql]
----
{ person { skills(filter: {skill: {name_starts_with: "F"}}) { skill { name } proficiencyLevel }}}
----

.Cypher Params
[source,json]
----
{
"personSkillsSkillNameStartsWith" : "F"
}
----

.Cypher
[source,cypher]
----
MATCH (person:Person)
CALL {
WITH person
MATCH (person)-[personSkills:HAS_SKILL]->(personSkillsSkill:Skill)
WHERE personSkillsSkill.name STARTS WITH $personSkillsSkillNameStartsWith
RETURN collect(personSkills {
skill: personSkillsSkill {
.name
},
.proficiencyLevel
}) AS personSkills
}
RETURN person {
skills: personSkills
} AS person
----

'''

=== Cascaded filter object string _eq_

.GraphQL-Query
Expand Down