Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
Expand Down
5 changes: 2 additions & 3 deletions src/test/resources/dynamic-property-tests.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,7 @@ mutation {
[source,cypher]
----
MATCH (updatePerson:Person { id: $updatePersonId })
SET updatePerson = {
id: $updatePersonId,
SET updatePerson += {
`properties.foo`: $updatePersonJsonFoo,
`properties.x`: $updatePersonJsonX
}
Expand Down Expand Up @@ -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]]])
Expand Down
2 changes: 1 addition & 1 deletion src/test/resources/movie-tests.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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
----
Expand Down
4 changes: 2 additions & 2 deletions src/test/resources/translator-tests-custom-scalars.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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
----
Expand Down Expand Up @@ -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
----
Expand Down