diff --git a/src/main/kotlin/org/neo4j/graphql/handler/MergeOrUpdateHandler.kt b/src/main/kotlin/org/neo4j/graphql/handler/MergeOrUpdateHandler.kt index d50bcbb5..1bf8bff4 100644 --- a/src/main/kotlin/org/neo4j/graphql/handler/MergeOrUpdateHandler.kt +++ b/src/main/kotlin/org/neo4j/graphql/handler/MergeOrUpdateHandler.kt @@ -67,13 +67,8 @@ class MergeOrUpdateHandler private constructor( } init { - defaultFields.clear() // for marge or updates we do not reset to defaults - if (idField.isNativeId() || merge) { - // native id cannot be updated - // if the ID is not a native ID and we are in the update mode, we do not remove it from the properties - // b/c otherwise the id field will be unset - propertyFields.remove(idField.name) - } + defaultFields.clear() // for merge or updates we do not reset to defaults + propertyFields.remove(idField.name) // id should not be updated } override fun generateCypher(variable: String, field: Field, env: DataFetchingEnvironment): Cypher { @@ -82,10 +77,9 @@ class MergeOrUpdateHandler private constructor( val properties = properties(variable, field.arguments) val mapProjection = projectFields(variable, field, type, env, null) - val op = if (merge) "+" else "" val select = getSelectQuery(variable, label(), idArg, idField, isRelation) return Cypher((if (merge && !idField.isNativeId()) "MERGE " else "MATCH ") + select.query + - " SET $variable $op= " + properties.query + + " SET $variable += " + properties.query + " WITH $variable" + " RETURN ${mapProjection.query} AS $variable", select.params + properties.params + mapProjection.params) diff --git a/src/test/resources/dynamic-property-tests.adoc b/src/test/resources/dynamic-property-tests.adoc index 3dcb1323..4c0b1a07 100644 --- a/src/test/resources/dynamic-property-tests.adoc +++ b/src/test/resources/dynamic-property-tests.adoc @@ -104,8 +104,7 @@ mutation { [source,cypher] ---- MATCH (updatePerson:Person { id: $updatePersonId }) -SET updatePerson = { - id: $updatePersonId, +SET updatePerson += { `properties.foo`: $updatePersonJsonFoo, `properties.x`: $updatePersonJsonX } @@ -209,7 +208,7 @@ mutation { ---- MATCH ()-[updateKnows:KNOWS]->() WHERE ID(updateKnows) = toInteger($updateKnows_id) -SET updateKnows = { `prefix.foo`: $updateKnowsJsonFoo } +SET updateKnows += { `prefix.foo`: $updateKnowsJsonFoo } WITH updateKnows RETURN updateKnows { json:apoc.map.fromPairs([key IN keys(updateKnows) WHERE key STARTS WITH 'prefix.'| [substring(key,7), updateKnows[key]]]) diff --git a/src/test/resources/movie-tests.adoc b/src/test/resources/movie-tests.adoc index 6f505045..ee63ecc0 100644 --- a/src/test/resources/movie-tests.adoc +++ b/src/test/resources/movie-tests.adoc @@ -940,7 +940,7 @@ mutation { ---- MATCH ()-[updateRated:RATED]->() WHERE ID(updateRated) = toInteger($updateRated_id) -SET updateRated = { rating: $updateRatedRating } +SET updateRated += { rating: $updateRatedRating } WITH updateRated RETURN updateRated { .rating } AS updateRated ---- diff --git a/src/test/resources/translator-tests-custom-scalars.adoc b/src/test/resources/translator-tests-custom-scalars.adoc index 1095ceed..cc433747 100644 --- a/src/test/resources/translator-tests-custom-scalars.adoc +++ b/src/test/resources/translator-tests-custom-scalars.adoc @@ -73,7 +73,7 @@ mutation { ---- MATCH (updateMovie: Movie) WHERE ID(updateMovie) = toInteger($updateMovie_id) -SET updateMovie = { released: $updateMovieReleased } +SET updateMovie += { released: $updateMovieReleased } WITH updateMovie RETURN updateMovie { .title, .released } AS updateMovie ---- @@ -137,7 +137,7 @@ mutation { ---- MATCH (updateMovie: Movie) WHERE ID(updateMovie) = toInteger($updateMovie_id) -SET updateMovie = { released: $updateMovieReleased } +SET updateMovie += { released: $updateMovieReleased } WITH updateMovie RETURN updateMovie { .title, .released } AS updateMovie ----