Skip to content

Commit eee081e

Browse files
authored
Fix sorting of relations (#249)
This fix ensures that sorting relational fields will work correctly
1 parent a388606 commit eee081e

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -565,9 +565,11 @@ open class ProjectionBase(
565565

566566
val (projectionEntries, sub) = projectFields(endNodePattern, name(childVariable), field, nodeType, env, variableSuffix)
567567

568+
val withPassThrough = mutableListOf(endNodePattern.requiredSymbolicName)
568569
var relationship = relInfo.createRelation(anyNode(variable), endNodePattern)
569570
if (isRelFromType) {
570571
relationship = relationship.named(childVariableName)
572+
withPassThrough.add(childVariableName)
571573
}
572574

573575
val with = with(variable)
@@ -582,8 +584,8 @@ open class ProjectionBase(
582584
val ordering = orderBy(childVariableName, field.arguments, fieldDefinition, env.variables)
583585
val skipLimit = SkipLimit(childVariable, field.arguments, fieldDefinition)
584586
reading = when {
585-
ordering != null -> skipLimit.format(reading.with(childVariableName).orderBy(*ordering.toTypedArray()))
586-
skipLimit.applies() -> skipLimit.format(reading.with(childVariableName))
587+
ordering != null -> skipLimit.format(reading.with(*withPassThrough.toTypedArray()).orderBy(*ordering.toTypedArray()))
588+
skipLimit.applies() -> skipLimit.format(reading.with(*withPassThrough.toTypedArray()))
587589
else -> reading
588590
}
589591
reading.withSubQueries(sub).returning(collect(childVariableName.project(projectionEntries)).`as`(childVariableName))

core/src/test/resources/translator-tests3.adoc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ CREATE
4242
{user( filter: {name_in: ["Jane", "Thomas"]}) {
4343
name
4444
referredBy { referralDate referredBy {name} }
45-
referred { referralDate user {name} }
45+
referred(orderBy: [referralDate_desc]) { referralDate user {name} }
4646
} }
4747
----
4848

@@ -108,6 +108,7 @@ CALL {
108108
CALL {
109109
WITH user
110110
MATCH (user)<-[userReferred:REFERRED_BY]-(userReferredUser:User)
111+
WITH userReferredUser, userReferred ORDER BY userReferred.referralDate DESC
111112
RETURN collect(userReferred {
112113
.referralDate,
113114
user: userReferredUser {

0 commit comments

Comments
 (0)