Ask a Question

Delete Mutations

Delete Mutations allow 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 types in the schema for the delete mutation. Delete mutations take 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.