You are looking at the docs for the unreleased master branch of Dgraph. The latest version is v20.07.
Report Issue Edit Page

Deep Mutations

Mutations also allows to perform deep mutation at multiple levels.

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
}

Example: Deep Deep mutation using variables

mutation DeepAuthor($author: DeepAuthorInput!) {
  DeepAuthor(input: [$author]) {
    author {
      id
      name
      post {
        title
        text
      }
    }
  }
}

Variables:

{ "author":
  { "name": "A.N. Author",
    "dob": "2000-01-01",
    "posts": [
      {
        "title": "New post",
        "text": "A really new post"
      }
    ]
  }
}

Example: Deep update mutation using variables

mutation updateAuthor($patch: UpdateAuthorInput!) {
  updateAuthor(input: $patch) {
    author {
      id
      post {
        title
        text
      }
    }
  }
}

Variables:

{ "patch":
  { "filter": {
      "id": ["0x123"]
    },
    "set": {
      "posts": [ {
        "postID": "0x456",
        "title": "A new title",
        "text": "Some edited text"
      } ]
    }
  }
}