Skip to content

Commit

Permalink
Fix Issue #299 mutation translation for IDs with @Property (#300)
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmathews authored Sep 8, 2023
1 parent 43633de commit dbeeeba
Show file tree
Hide file tree
Showing 2 changed files with 208 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,10 @@ abstract class BaseDataFetcherForContainer(schemaConfig: SchemaConfig) : BaseDat
propContainer to where
} else {
val node = node(label).named(variable)
// TODO handle @property aliasing
if (idProperty.value is ArrayValue) {
node to node.property(idField.name).`in`(idParam)
node to node.property(idField.propertyName()).`in`(idParam)
} else {
node.withProperties(idField.name, idParam) to Conditions.noCondition()
node.withProperties(idField.propertyName(), idParam) to Conditions.noCondition()
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,206 @@
:toc:

= GitHub Issue #299: Incorrect mutation translation for IDs with @property

== Schema

[source,graphql,schema=true]
----
type Person {
id: ID! @property(name: "~id")
name: String
actedIn: [Movie!]! @relation(name: "ACTED_IN", direction:OUT)
}
type Movie {
title: ID!
}
----

== Merge Mutation

.GraphQL-Query
[source,graphql]
----
mutation {
mergePerson(id: "test-id", name: "test-name") {
id
}
}
----

.Cypher Params
[source,json]
----
{
"mergePersonId": "test-id",
"mergePersonName": "test-name"
}
----

.Cypher
[source,cypher]
----
MERGE (mergePerson:Person {
`~id`: $mergePersonId
})
SET mergePerson += {
name: $mergePersonName
}
WITH mergePerson
RETURN mergePerson {
id: mergePerson.`~id`
} AS mergePerson
----

'''

== Update Mutation

.GraphQL-Query
[source,graphql]
----
mutation {
updatePerson(id: "test-id", name: "other-test-name") {
id
}
}
----

.Cypher Params
[source,json]
----
{
"updatePersonId": "test-id",
"updatePersonName": "other-test-name"
}
----

.Cypher
[source,cypher]
----
MATCH (updatePerson:Person {
`~id`: $updatePersonId
})
SET updatePerson += {
name: $updatePersonName
}
WITH updatePerson
RETURN updatePerson {
id: updatePerson.`~id`
} AS updatePerson
----

'''

== Delete Mutation

.GraphQL-Query
[source,graphql]
----
mutation {
deletePerson(id: "test-id") {
id
}
}
----

.Cypher Params
[source,json]
----
{
"deletePersonId": "test-id"
}
----

.Cypher
[source,cypher]
----
MATCH (deletePerson:Person {
`~id`: $deletePersonId
})
WITH deletePerson AS toDelete, deletePerson {
id: deletePerson.`~id`
} AS deletePerson DETACH DELETE toDelete
RETURN deletePerson AS deletePerson
----

'''

== Add Relationship Mutation

.GraphQL-Query
[source,graphql]
----
mutation {
addPersonActedIn(id: "test-id", actedIn: "test-movie") {
id
}
}
----

.Cypher Params
[source,json]
----
{
"fromId": "test-id",
"toActedIn": "test-movie"
}
----

.Cypher
[source,cypher]
----
MATCH (from:Person {
`~id`: $fromId
})
MATCH (to:Movie {
title: $toActedIn
})
MERGE (from)-[:ACTED_IN]->(to)
WITH DISTINCT from AS addPersonActedIn
RETURN addPersonActedIn {
id: addPersonActedIn.`~id`
} AS addPersonActedIn
----

'''

== Delete Relationship Mutation

.GraphQL-Query
[source,graphql]
----
mutation {
deletePersonActedIn(id: "test-id", actedIn: "test-movie") {
id
}
}
----

.Cypher Params
[source,json]
----
{
"fromId": "test-id",
"toActedIn": "test-movie"
}
----

.Cypher
[source,cypher]
----
MATCH (from:Person {
`~id`: $fromId
})
MATCH (to:Movie {
title: $toActedIn
})
MATCH (from)-[r:ACTED_IN]->(to) DELETE r
WITH DISTINCT from AS deletePersonActedIn
RETURN deletePersonActedIn {
id: deletePersonActedIn.`~id`
} AS deletePersonActedIn
----

'''

0 comments on commit dbeeeba

Please sign in to comment.