Skip to content

Allow to filter relation by interface #230

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
Jun 3, 2021
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
5 changes: 2 additions & 3 deletions core/src/main/kotlin/org/neo4j/graphql/parser/QueryParser.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package org.neo4j.graphql.parser
import graphql.language.*
import graphql.schema.GraphQLFieldDefinition
import graphql.schema.GraphQLFieldsContainer
import graphql.schema.GraphQLObjectType
import org.neo4j.cypherdsl.core.*
import org.neo4j.cypherdsl.core.Node
import org.neo4j.graphql.*
Expand Down Expand Up @@ -69,14 +68,14 @@ class RelationPredicate(
) : Predicate<RelationOperator>(op, queryField, normalizeName(fieldDefinition.name, op.suffix.toCamelCase()), index) {

val relationshipInfo = type.relationshipFor(fieldDefinition.name)!!
val relNode: Node = CypherDSL.node((fieldDefinition.type.inner() as? GraphQLObjectType)?.label()!!)
val relNode: Node = CypherDSL.node(fieldDefinition.type.getInnerFieldsContainer().label())

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

fun createExistsCondition(propertyContainer: PropertyContainer): Condition {
val relation = createRelation(propertyContainer as? Node
?: throw IllegalStateException("""propertyContainer is expected to be a Node but was ${propertyContainer.javaClass.name}"""))
val condition = CypherDSL.match(relation).asCondition()
val condition = CypherDSL.match(relation).asCondition()
return when (op) {
RelationOperator.NOT -> condition
RelationOperator.EQ_OR_NOT_EXISTS -> condition.not()
Expand Down
67 changes: 67 additions & 0 deletions core/src/test/resources/issues/gh-210.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
:toc:

= Github Issue #210: Nested filters are not working

== Schema

[source,graphql,schema=true]
----
interface Period {
id: String!
value: Int!
in: [Period] @relation(name: "IN_PERIOD", direction: OUT)
}

type Week implements Period {
id: String!
value: Int!
in: [Period] @relation(name: "IN_PERIOD", direction: OUT)
}
----

== Configuration

.Configuration
[source,json,schema-config=true]
----
{
"capitalizeQueryFields": true
}
----

== Test

.GraphQL-Query
[source,graphql]
----
{
Week(
filter: {
in: { value:2020 }
}
)
{
id
}
}
----

.Cypher Params
[source,json]
----
{
"filterWeekPeriodValue" : 2020
}
----

.Cypher
[source,cypher]
----
MATCH (week:Week)
WHERE all(filterWeekPeriodCond IN [(week)-[:IN_PERIOD]->(filterWeekPeriod:Period) | filterWeekPeriod.value = $filterWeekPeriodValue]
WHERE filterWeekPeriodCond)
RETURN week {
.id
} AS Week
----