Skip to content
This repository has been archived by the owner on Sep 2, 2022. It is now read-only.

Cannot delete nodes with relations #1795

Closed
nickluger opened this issue Jan 31, 2018 · 8 comments
Closed

Cannot delete nodes with relations #1795

nickluger opened this issue Jan 31, 2018 · 8 comments

Comments

@nickluger
Copy link

nickluger commented Jan 31, 2018

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.

@nickluger nickluger changed the title The field 'x' on type 'y' is required - on empty relation. Cannot delete nodes with relation- "The field 'x' on type 'y' is required" - on empty relation. Jan 31, 2018
@nickluger nickluger changed the title Cannot delete nodes with relation- "The field 'x' on type 'y' is required" - on empty relation. Cannot delete nodes with relations Jan 31, 2018
@honzavalustik
Copy link

Running into the same issue with Prisma. In Graphcool framework this was working so I guess it should be in Prisma too.

@Fi1osof
Copy link

Fi1osof commented Feb 1, 2018

@johhansantana
Copy link

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.

@marktani
Copy link
Contributor

marktani commented Feb 1, 2018

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.

@nickluger
Copy link
Author

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.

@do4gr
Copy link
Member

do4gr commented Feb 2, 2018

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.

@emipc
Copy link

emipc commented Feb 4, 2018

Any idea of when this fix will be released?

@marktani
Copy link
Contributor

marktani commented Feb 6, 2018

This has now been release in 1.1.3 🙂

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

8 participants