Skip to content

Commit 4792d3f

Browse files
authored
Fixes the issue that an update removes the custom ID field on the node (resolves #95) (#96)
1 parent c4a7f2d commit 4792d3f

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class MergeOrUpdateHandler private constructor(
3131
}
3232

3333
override fun createDataFetcher(rootType: GraphQLObjectType, fieldDefinition: GraphQLFieldDefinition): DataFetcher<Cypher>? {
34-
if (rootType.name != MUTATION){
34+
if (rootType.name != MUTATION) {
3535
return null
3636
}
3737
if (fieldDefinition.cypherDirective() != null) {
@@ -67,8 +67,13 @@ class MergeOrUpdateHandler private constructor(
6767
}
6868

6969
init {
70-
defaultFields.clear()
71-
propertyFields.remove(idField.name) // id should not be updated
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+
}
7277
}
7378

7479
override fun generateCypher(variable: String, field: Field, env: DataFetchingEnvironment): Cypher {

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ mutation {
105105
----
106106
MATCH (updatePerson:Person { id: $updatePersonId })
107107
SET updatePerson = {
108+
id: $updatePersonId,
108109
`properties.foo`: $updatePersonJsonFoo,
109110
`properties.x`: $updatePersonJsonX
110111
}
@@ -245,4 +246,4 @@ SET mergeKnows += { `prefix.foo`: $mergeKnowsJsonFoo }
245246
WITH mergeKnows RETURN mergeKnows {
246247
json:apoc.map.fromPairs([key IN keys(mergeKnows) WHERE key STARTS WITH 'prefix.'| [substring(key,7), mergeKnows[key]]])
247248
} AS mergeKnows
248-
----
249+
----

0 commit comments

Comments
 (0)