Running this GraphQL mutation
"Convenience mutation to destructively update DataPoints for a specific SurveyResponse and question. Accepts answers and/or value. This mutation deletes existing relationships that represent answer data. Returns a DataPoint."
AnswerQuestion(
"The id of the question"
id: ID!
surveyResponse: ID!
answers: [ID] = []
value: String = null
): DataPoint
@hasScope(scopes: ["DataPoint: Update"])
@cypher(
statement: """
MATCH (sr:SurveyResponse) WHERE sr.id = $surveyResponse
MATCH (q:Question) WHERE q.id = $id
OPTIONAL MATCH (sr)--(oldDp:DataPoint)--(q)
DETACH DELETE oldDp
MERGE (sr)-[:HAS_DATA_POINT]->(dp:DataPoint {id: coalesce(dp.id, apoc.create.uuid())})-[:FOR_QUESTION]->(q)
WITH dp, q
FOREACH (o IN CASE WHEN $value IS NOT NULL THEN [true] ELSE [] END | MERGE (dp)-[:ANSWERS {value: $value, propToWrite: q.propToWrite}]->(q))
WITH dp, q
OPTIONAL MATCH (a:Answer) WHERE a.id IN $answers
FOREACH (o IN CASE WHEN a IS NOT NULL THEN [a] ELSE [] END | MERGE (dp)-[:SELECTED_ANSWER]->(a))
RETURN dp
"""
)
results in this type of error message on aura (4.2.0. enterprise edition - no matter whether this is run against leader or follower nodes):
Failed to invoke procedure
apoc.cypher.doIt
: Caused by: IndexEntryConflictException{propertyValues=( String("always-the-same-id-that-has-nothing-to-do-with-the-queried-data") ), addedNodeId=-1, existingNodeId=n}``` where "always-the-same-id-that-has-nothing-to-do-with-the-queried-data" and "n" are unimportant values.
The same mutation works fine on localhost (4.2.7 community edition).
When I query on all nodes for the id ("always-the-same-id-that-has-nothing-to-do-with-the-queried-data"), I see one DataPoint and another node which are not connected. Deleting the DataPoint and just running the reduced query below in neo directly yields the same error message.
MATCH (sr:SurveyResponse) WHERE sr.id = $surveyResponse
MATCH (q:Question) WHERE q.id = $id
OPTIONAL MATCH (sr)--(oldDp:DataPoint)--(q)
DETACH DELETE oldDp
MERGE (sr)-[:HAS_DATA_POINT]->(dp:DataPoint {id: coalesce(dp.id, apoc.create.uuid())})-[:FOR_QUESTION]->(q) RETURN dp
This let me to believe that the uuid creation on aura is flawed, but running RETURN apoc.create.uuid()
multiple times creates different strings. Sneaking in a WITH sr, q
between the DETACH DELETE and MERGE statements has no effect.
Thanks for being my rubber ducks.
This is the diff that made it work:
I'm sure there's a ton of optimizations to be done, but this is good enough for now and it works. Still no idea why aura just behaves so different at times.