Skip to content

Commit dbeeeba

Browse files
authored
Fix Issue #299 mutation translation for IDs with @Property (#300)
#299
1 parent 43633de commit dbeeeba

File tree

2 files changed

+208
-3
lines changed

2 files changed

+208
-3
lines changed

core/src/main/kotlin/org/neo4j/graphql/handler/BaseDataFetcherForContainer.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,10 @@ abstract class BaseDataFetcherForContainer(schemaConfig: SchemaConfig) : BaseDat
105105
propContainer to where
106106
} else {
107107
val node = node(label).named(variable)
108-
// TODO handle @property aliasing
109108
if (idProperty.value is ArrayValue) {
110-
node to node.property(idField.name).`in`(idParam)
109+
node to node.property(idField.propertyName()).`in`(idParam)
111110
} else {
112-
node.withProperties(idField.name, idParam) to Conditions.noCondition()
111+
node.withProperties(idField.propertyName(), idParam) to Conditions.noCondition()
113112
}
114113
}
115114
}
Lines changed: 206 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,206 @@
1+
:toc:
2+
3+
= GitHub Issue #299: Incorrect mutation translation for IDs with @property
4+
5+
== Schema
6+
7+
[source,graphql,schema=true]
8+
----
9+
type Person {
10+
id: ID! @property(name: "~id")
11+
name: String
12+
actedIn: [Movie!]! @relation(name: "ACTED_IN", direction:OUT)
13+
}
14+
15+
type Movie {
16+
title: ID!
17+
}
18+
----
19+
20+
== Merge Mutation
21+
22+
.GraphQL-Query
23+
[source,graphql]
24+
----
25+
mutation {
26+
mergePerson(id: "test-id", name: "test-name") {
27+
id
28+
}
29+
}
30+
----
31+
32+
.Cypher Params
33+
[source,json]
34+
----
35+
{
36+
"mergePersonId": "test-id",
37+
"mergePersonName": "test-name"
38+
}
39+
----
40+
41+
.Cypher
42+
[source,cypher]
43+
----
44+
MERGE (mergePerson:Person {
45+
`~id`: $mergePersonId
46+
})
47+
SET mergePerson += {
48+
name: $mergePersonName
49+
}
50+
WITH mergePerson
51+
RETURN mergePerson {
52+
id: mergePerson.`~id`
53+
} AS mergePerson
54+
----
55+
56+
'''
57+
58+
== Update Mutation
59+
60+
.GraphQL-Query
61+
[source,graphql]
62+
----
63+
mutation {
64+
updatePerson(id: "test-id", name: "other-test-name") {
65+
id
66+
}
67+
}
68+
----
69+
70+
.Cypher Params
71+
[source,json]
72+
----
73+
{
74+
"updatePersonId": "test-id",
75+
"updatePersonName": "other-test-name"
76+
}
77+
----
78+
79+
.Cypher
80+
[source,cypher]
81+
----
82+
MATCH (updatePerson:Person {
83+
`~id`: $updatePersonId
84+
})
85+
SET updatePerson += {
86+
name: $updatePersonName
87+
}
88+
WITH updatePerson
89+
RETURN updatePerson {
90+
id: updatePerson.`~id`
91+
} AS updatePerson
92+
----
93+
94+
'''
95+
96+
== Delete Mutation
97+
98+
.GraphQL-Query
99+
[source,graphql]
100+
----
101+
mutation {
102+
deletePerson(id: "test-id") {
103+
id
104+
}
105+
}
106+
----
107+
108+
.Cypher Params
109+
[source,json]
110+
----
111+
{
112+
"deletePersonId": "test-id"
113+
}
114+
----
115+
116+
.Cypher
117+
[source,cypher]
118+
----
119+
MATCH (deletePerson:Person {
120+
`~id`: $deletePersonId
121+
})
122+
WITH deletePerson AS toDelete, deletePerson {
123+
id: deletePerson.`~id`
124+
} AS deletePerson DETACH DELETE toDelete
125+
RETURN deletePerson AS deletePerson
126+
----
127+
128+
'''
129+
130+
== Add Relationship Mutation
131+
132+
.GraphQL-Query
133+
[source,graphql]
134+
----
135+
mutation {
136+
addPersonActedIn(id: "test-id", actedIn: "test-movie") {
137+
id
138+
}
139+
}
140+
----
141+
142+
.Cypher Params
143+
[source,json]
144+
----
145+
{
146+
"fromId": "test-id",
147+
"toActedIn": "test-movie"
148+
}
149+
----
150+
151+
.Cypher
152+
[source,cypher]
153+
----
154+
MATCH (from:Person {
155+
`~id`: $fromId
156+
})
157+
MATCH (to:Movie {
158+
title: $toActedIn
159+
})
160+
MERGE (from)-[:ACTED_IN]->(to)
161+
WITH DISTINCT from AS addPersonActedIn
162+
RETURN addPersonActedIn {
163+
id: addPersonActedIn.`~id`
164+
} AS addPersonActedIn
165+
----
166+
167+
'''
168+
169+
== Delete Relationship Mutation
170+
171+
.GraphQL-Query
172+
[source,graphql]
173+
----
174+
mutation {
175+
deletePersonActedIn(id: "test-id", actedIn: "test-movie") {
176+
id
177+
}
178+
}
179+
----
180+
181+
.Cypher Params
182+
[source,json]
183+
----
184+
{
185+
"fromId": "test-id",
186+
"toActedIn": "test-movie"
187+
}
188+
----
189+
190+
.Cypher
191+
[source,cypher]
192+
----
193+
MATCH (from:Person {
194+
`~id`: $fromId
195+
})
196+
MATCH (to:Movie {
197+
title: $toActedIn
198+
})
199+
MATCH (from)-[r:ACTED_IN]->(to) DELETE r
200+
WITH DISTINCT from AS deletePersonActedIn
201+
RETURN deletePersonActedIn {
202+
id: deletePersonActedIn.`~id`
203+
} AS deletePersonActedIn
204+
----
205+
206+
'''

0 commit comments

Comments
 (0)