Skip to content

Commit fc8f780

Browse files
authored
Allow to filter relation by interface (#230)
resolves #210
1 parent 0e351d0 commit fc8f780

File tree

2 files changed

+69
-3
lines changed

2 files changed

+69
-3
lines changed

core/src/main/kotlin/org/neo4j/graphql/parser/QueryParser.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package org.neo4j.graphql.parser
33
import graphql.language.*
44
import graphql.schema.GraphQLFieldDefinition
55
import graphql.schema.GraphQLFieldsContainer
6-
import graphql.schema.GraphQLObjectType
76
import org.neo4j.cypherdsl.core.*
87
import org.neo4j.cypherdsl.core.Node
98
import org.neo4j.graphql.*
@@ -69,14 +68,14 @@ class RelationPredicate(
6968
) : Predicate<RelationOperator>(op, queryField, normalizeName(fieldDefinition.name, op.suffix.toCamelCase()), index) {
7069

7170
val relationshipInfo = type.relationshipFor(fieldDefinition.name)!!
72-
val relNode: Node = CypherDSL.node((fieldDefinition.type.inner() as? GraphQLObjectType)?.label()!!)
71+
val relNode: Node = CypherDSL.node(fieldDefinition.type.getInnerFieldsContainer().label())
7372

7473
fun createRelation(start: Node): Relationship = relationshipInfo.createRelation(start, relNode)
7574

7675
fun createExistsCondition(propertyContainer: PropertyContainer): Condition {
7776
val relation = createRelation(propertyContainer as? Node
7877
?: throw IllegalStateException("""propertyContainer is expected to be a Node but was ${propertyContainer.javaClass.name}"""))
79-
val condition = CypherDSL.match(relation).asCondition()
78+
val condition = CypherDSL.match(relation).asCondition()
8079
return when (op) {
8180
RelationOperator.NOT -> condition
8281
RelationOperator.EQ_OR_NOT_EXISTS -> condition.not()
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
:toc:
2+
3+
= Github Issue #210: Nested filters are not working
4+
5+
== Schema
6+
7+
[source,graphql,schema=true]
8+
----
9+
interface Period {
10+
id: String!
11+
value: Int!
12+
in: [Period] @relation(name: "IN_PERIOD", direction: OUT)
13+
}
14+
15+
type Week implements Period {
16+
id: String!
17+
value: Int!
18+
in: [Period] @relation(name: "IN_PERIOD", direction: OUT)
19+
}
20+
----
21+
22+
== Configuration
23+
24+
.Configuration
25+
[source,json,schema-config=true]
26+
----
27+
{
28+
"capitalizeQueryFields": true
29+
}
30+
----
31+
32+
== Test
33+
34+
.GraphQL-Query
35+
[source,graphql]
36+
----
37+
{
38+
Week(
39+
filter: {
40+
in: { value:2020 }
41+
}
42+
)
43+
{
44+
id
45+
}
46+
}
47+
----
48+
49+
.Cypher Params
50+
[source,json]
51+
----
52+
{
53+
"filterWeekPeriodValue" : 2020
54+
}
55+
----
56+
57+
.Cypher
58+
[source,cypher]
59+
----
60+
MATCH (week:Week)
61+
WHERE all(filterWeekPeriodCond IN [(week)-[:IN_PERIOD]->(filterWeekPeriod:Period) | filterWeekPeriod.value = $filterWeekPeriodValue]
62+
WHERE filterWeekPeriodCond)
63+
RETURN week {
64+
.id
65+
} AS Week
66+
----
67+

0 commit comments

Comments
 (0)