Skip to content

Commit 3c7b726

Browse files
Andy2003jexp
authored andcommitted
fix string handling for native ID (#68)
1 parent adcd552 commit 3c7b726

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

src/main/kotlin/org/neo4j/graphql/Predicates.kt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,12 @@ data class ExpressionPredicate(val name: String, val op: Operators, val value: A
7272
val not = if (op.not) "NOT " else ""
7373
override fun toExpression(variable: String): Cypher {
7474
val paramName: String = ProjectionBase.FILTER + paramName(variable, name, value).capitalize()
75-
val field = if (fieldDefinition.isNativeId()) "ID($variable)" else "$variable.${name.quote()}"
76-
return Cypher("$not$field ${op.op} \$$paramName", mapOf(paramName to value))
75+
val query = if (fieldDefinition.isNativeId()) {
76+
"${not}ID($variable) ${op.op} toInteger(\$$paramName)"
77+
} else {
78+
"$not$variable.${name.quote()} ${op.op} \$$paramName"
79+
}
80+
return Cypher(query, mapOf(paramName to value))
7781
}
7882
}
7983

src/main/kotlin/org/neo4j/graphql/handler/BaseDataFetcher.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,9 @@ abstract class BaseDataFetcher(
127127
val queryParams = mapOf(paramName to idProperty.value.toJavaValue())
128128
if (idField.isNativeId()) {
129129
if (isRelation) {
130-
Cypher("()-[$variable:$label]->() WHERE ID($variable) = $$paramName", queryParams)
130+
Cypher("()-[$variable:$label]->() WHERE ID($variable) = toInteger($$paramName)", queryParams)
131131
} else {
132-
Cypher("($variable:$label) WHERE ID($variable) = $$paramName", queryParams)
132+
Cypher("($variable:$label) WHERE ID($variable) = toInteger($$paramName)", queryParams)
133133
}
134134
} else {
135135
// TODO handle @property aliasing

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ open class ProjectionBase {
4848
// todo turn it into a Predicate too
4949
val eqExpression = noFilter.map {
5050
if (type.getFieldDefinition(it.name)?.isNativeId() == true)
51-
"ID($variable) = \$${paramName(variable, it.propertyName, it.value)}"
51+
"ID($variable) = toInteger(\$${paramName(variable, it.propertyName, it.value)})"
5252
else
5353
"$variable.${it.toCypherString(variable, false)}"
5454
}

0 commit comments

Comments
 (0)