I have two types
type Question {
id: ID! @unique
answers: [Answer!]!
title: String!
}
type Answer {
id: ID! @unique
question: Question!
title: String!
}
If i run:
{
questions {
id,
answers {
id
}
}
}
i receive:
{
"data": {
"questions": [
{
"id": "cjd3cojbs002y0105lypqn9ts",
"answers": []
}
]
}
}
if i run:
mutation {
deleteQuestion(where: {id:"cjd3cojbs002y0105lypqn9ts"}) {
id
}
}
i get:
{
"data": {
"deleteQuestion": null
},
"errors": [
{
"locations": [
{
"line": 2,
"column": 3
}
],
"path": [
"deleteQuestion"
],
"code": 3032,
"message": "The field 'question' on type 'Answer' is required. Performing this mutation would violate that constraint",
"requestId": "api:api:cjd3d4mwa00530105z9z8g2r3"
}
]
}
Why's that? There are no answers.
Running into the same issue with Prisma. In Graphcool framework this was working so I guess it should be in Prisma too.
This is because the relation in Answer has a required question, therefore, if you delete the question, it will result in it having null for an answer.
There should be a way to be able to tell prisms what to do on deleting nodes with relations, like delete the relations as well or what not.
I can confirm that this is unexpected behaviour.
@johhansantana the key point here is that there are no Answer nodes, so deleting a Question node should work. You might also be interested in #1262, which we're currently working on.
Exactly, @marktani. Yes i follow #1262 and cascading deletes or orphaned nodes are a great feature, but i think this here is a very urgent bug, as one cannot delete any nodes in the database. (that have parent-child relationship - that is a lot of things...). I mean the D from CRUD is basically broken. I wonder why there's no unit test covering this.
Thanks for bringing this up @nickluger. As part of our work to implement cascading deletes we already reworked how the top-level delete verifies relations and added test coverage for this. We will merge the current state of the Cascading Deletes PR https://github.com/graphcool/prisma/pull/1764 since it fixes this bug. The implementation of Cascading Deletes will then continue in a separate PR.
Any idea of when this fix will be released?
This has now been release in 1.1.3 馃檪
Most helpful comment
This has now been release in
1.1.3馃檪