Delete Mutations allows you to delete objects of a particular type.
We use the following schema to demonstrate some examples.
Schema:
type Author {
id: ID!
name: String! @search(by: [hash])
dob: DateTime
posts: [Post]
}
type Post {
postID: ID!
title: String! @search(by: [term, fulltext])
text: String @search(by: [fulltext, term])
datePublished: DateTime
}
Dgraph automatically generates input and return type in the schema for the delete mutation. Delete Mutations takes filter as an input to select specific objects and returns the state of the objects before deletion.
deleteAuthor(filter: AuthorFilter!): DeleteAuthorPayload
type DeleteAuthorPayload {
author(filter: AuthorFilter, order: AuthorOrder, first: Int, offset: Int): [Author]
msg: String
numUids: Int
}
Example: Delete mutation using variables
mutation deleteAuthor($filter: AuthorFilter!) {
deleteAuthor(filter: $filter) {
msg
author {
name
dob
}
}
}
Variables:
{ "filter":
{ "name": { "eq": "A.N. Author" } }
}
Examples
You can refer to the following link for more examples.
This is a companion discussion topic for the original entry at https://dgraph.io/docs/graphql/mutations/delete/