Skip to content
This repository was archived by the owner on Apr 17, 2023. It is now read-only.
This repository was archived by the owner on Apr 17, 2023. It is now read-only.

How to set on delete cascade in .graphql file #2277

Description

@rrguhan6

I'm using postgres 11.10

My model is

""" 
@model
"""
type Note  {
  """ @id """
  id: ID!
  title: String!
  description: String
   """
  @oneToMany(field: 'note')
  """
  comments: [Comment]
}

""" 
@model(delete: true)
 """
type Comment {
  """ @id """
  id: ID!
  text: String
  description: String
}

type Query {
  getDraftNotes: [Note]
}

Query :

mutation{
  deleteNote(input:{id:1}){
    id
    title
    description
  }
}

output:

{
  "errors": [
    {
      "message": "delete from \"note\" where \"id\" = $1 returning * - update or delete on table \"note\" violates foreign key constraint \"comment_noteid_foreign\" on table \"comment\"",
      "locations": [
        {
          "line": 2,
          "column": 3
        }
      ],
      "path": [
        "deleteNote"
      ],
      "extensions": {
        "code": "INTERNAL_SERVER_ERROR",
        "exception": {
          "length": 274,
          "name": "error",
          "severity": "ERROR",
          "code": "23503",
          "detail": "Key (id)=(1) is still referenced from table \"comment\".",
          "schema": "public",
          "table": "comment",
          "constraint": "comment_noteid_foreign",
          "file": "ri_triggers.c",
          "line": "2797",
          "routine": "ri_ReportViolation",
          "stacktrace": [
            "error: delete from \"note\" where \"id\" = $1 returning * - update or delete on table \"note\" violates foreign key constraint \"comment_noteid_foreign\" on table \"comment\"",
            "    at Parser.parseErrorMessage (/home/guhan/code/gql-postgress/web/node_modules/pg-protocol/src/parser.ts:357:11)",
            "    at Parser.handlePacket (/home/guhan/code/gql-postgress/web/node_modules/pg-protocol/src/parser.ts:186:21)",
            "    at Parser.parse (/home/guhan/code/gql-postgress/web/node_modules/pg-protocol/src/parser.ts:101:30)",
            "    at Socket.stream.on (/home/guhan/code/gql-postgress/web/node_modules/pg-protocol/src/index.ts:7:48)",
            "    at Socket.emit (events.js:198:13)",
            "    at Socket.EventEmitter.emit (domain.js:448:20)",
            "    at addChunk (_stream_readable.js:288:12)",
            "    at readableAddChunk (_stream_readable.js:269:11)",
            "    at Socket.Readable.push (_stream_readable.js:224:10)",
            "    at TCP.onStreamRead [as onread] (internal/stream_base_commons.js:94:17)"
          ]
        }
      }
    }
  ],
  "data": {
    "deleteNote": null
  }
}

pls help me to resolve this

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions