Skip to content

Fixes the issue that an update removes the custom ID field on the node #96

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 22, 2020
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 @@ -31,7 +31,7 @@ class MergeOrUpdateHandler private constructor(
}

override fun createDataFetcher(rootType: GraphQLObjectType, fieldDefinition: GraphQLFieldDefinition): DataFetcher<Cypher>? {
if (rootType.name != MUTATION){
if (rootType.name != MUTATION) {
return null
}
if (fieldDefinition.cypherDirective() != null) {
Expand Down Expand Up @@ -67,8 +67,13 @@ class MergeOrUpdateHandler private constructor(
}

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

override fun generateCypher(variable: String, field: Field, env: DataFetchingEnvironment): Cypher {
Expand Down
3 changes: 2 additions & 1 deletion src/test/resources/dynamic-property-tests.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ mutation {
----
MATCH (updatePerson:Person { id: $updatePersonId })
SET updatePerson = {
id: $updatePersonId,
`properties.foo`: $updatePersonJsonFoo,
`properties.x`: $updatePersonJsonX
}
Expand Down Expand Up @@ -245,4 +246,4 @@ SET mergeKnows += { `prefix.foo`: $mergeKnowsJsonFoo }
WITH mergeKnows RETURN mergeKnows {
json:apoc.map.fromPairs([key IN keys(mergeKnows) WHERE key STARTS WITH 'prefix.'| [substring(key,7), mergeKnows[key]]])
} AS mergeKnows
----
----