delete

This is the documentation of the GraphQL Library version 6. For the long-term support (LTS) version 5, refer to GraphQL Library version 5 LTS.

Consider these type definitions:

type Post @node {
    id: ID! @id
    content: String!
    creator: User! @relationship(type: "HAS_POST", direction: IN)
}

type User @node {
    id: ID! @id
    name: String
    posts: [Post!]! @relationship(type: "HAS_POST", direction: OUT)
}

The following delete mutations and response types are generated:

type DeleteInfo {
    nodesDeleted: Int!
    relationshipsDeleted: Int!
}

type Mutation {
    deletePosts(where: PostWhere, delete: PostDeleteInput): DeleteInfo!
    deleteUsers(where: UserWhere, delete: UserDeleteInput): DeleteInfo!
}

The DeleteInfo type is the common return type for all delete mutations.

Single delete

You can delete a single post by executing the following GraphQL statement:

mutation {
    deletePosts(where: {
        id_EQ: "6042E807-47AE-4857-B7FE-1AADF522DE8B"
    }) {
        nodesDeleted
        relationshipsDeleted
    }
}

This deletes the post using the autogenerated ID that was returned after the creation of the post. Consequently, nodesDeleted is equal to 1 (the post) and relationshipsDeleted is also equal to 1 as the HAS_POST relationship between the Post and its author was deleted.

Nested delete

In case you want to delete a User and all of their posts, you can use a single nested delete mutation:

mutation {
  deleteUsers(where: { name_EQ: "Jane Doe" }, delete: { posts: {} }) {
    nodesDeleted
    relationshipsDeleted
  }
}