Skip to content

Commit b4867a5

Browse files
authored
This change fixes an issue (#105) where properties got unset for when updating a node. (#117)
Now we always use `SET x += {}` to update properties.
1 parent 9187d22 commit b4867a5

File tree

4 files changed

+8
-15
lines changed

4 files changed

+8
-15
lines changed

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

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,8 @@ class MergeOrUpdateHandler private constructor(
6767
}
6868

6969
init {
70-
defaultFields.clear() // for marge or updates we do not reset to defaults
71-
if (idField.isNativeId() || merge) {
72-
// native id cannot be updated
73-
// if the ID is not a native ID and we are in the update mode, we do not remove it from the properties
74-
// b/c otherwise the id field will be unset
75-
propertyFields.remove(idField.name)
76-
}
70+
defaultFields.clear() // for merge or updates we do not reset to defaults
71+
propertyFields.remove(idField.name) // id should not be updated
7772
}
7873

7974
override fun generateCypher(variable: String, field: Field, env: DataFetchingEnvironment): Cypher {
@@ -82,10 +77,9 @@ class MergeOrUpdateHandler private constructor(
8277
val properties = properties(variable, field.arguments)
8378
val mapProjection = projectFields(variable, field, type, env, null)
8479

85-
val op = if (merge) "+" else ""
8680
val select = getSelectQuery(variable, label(), idArg, idField, isRelation)
8781
return Cypher((if (merge && !idField.isNativeId()) "MERGE " else "MATCH ") + select.query +
88-
" SET $variable $op= " + properties.query +
82+
" SET $variable += " + properties.query +
8983
" WITH $variable" +
9084
" RETURN ${mapProjection.query} AS $variable",
9185
select.params + properties.params + mapProjection.params)

src/test/resources/dynamic-property-tests.adoc

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,7 @@ mutation {
104104
[source,cypher]
105105
----
106106
MATCH (updatePerson:Person { id: $updatePersonId })
107-
SET updatePerson = {
108-
id: $updatePersonId,
107+
SET updatePerson += {
109108
`properties.foo`: $updatePersonJsonFoo,
110109
`properties.x`: $updatePersonJsonX
111110
}
@@ -209,7 +208,7 @@ mutation {
209208
----
210209
MATCH ()-[updateKnows:KNOWS]->()
211210
WHERE ID(updateKnows) = toInteger($updateKnows_id)
212-
SET updateKnows = { `prefix.foo`: $updateKnowsJsonFoo }
211+
SET updateKnows += { `prefix.foo`: $updateKnowsJsonFoo }
213212
WITH updateKnows
214213
RETURN updateKnows {
215214
json:apoc.map.fromPairs([key IN keys(updateKnows) WHERE key STARTS WITH 'prefix.'| [substring(key,7), updateKnows[key]]])

src/test/resources/movie-tests.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -940,7 +940,7 @@ mutation {
940940
----
941941
MATCH ()-[updateRated:RATED]->()
942942
WHERE ID(updateRated) = toInteger($updateRated_id)
943-
SET updateRated = { rating: $updateRatedRating }
943+
SET updateRated += { rating: $updateRatedRating }
944944
WITH updateRated
945945
RETURN updateRated { .rating } AS updateRated
946946
----

src/test/resources/translator-tests-custom-scalars.adoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ mutation {
7373
----
7474
MATCH (updateMovie: Movie)
7575
WHERE ID(updateMovie) = toInteger($updateMovie_id)
76-
SET updateMovie = { released: $updateMovieReleased }
76+
SET updateMovie += { released: $updateMovieReleased }
7777
WITH updateMovie
7878
RETURN updateMovie { .title, .released } AS updateMovie
7979
----
@@ -137,7 +137,7 @@ mutation {
137137
----
138138
MATCH (updateMovie: Movie)
139139
WHERE ID(updateMovie) = toInteger($updateMovie_id)
140-
SET updateMovie = { released: $updateMovieReleased }
140+
SET updateMovie += { released: $updateMovieReleased }
141141
WITH updateMovie
142142
RETURN updateMovie { .title, .released } AS updateMovie
143143
----

0 commit comments

Comments
 (0)