Deep Mutations - Graphql

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"
      } ]
    }
  }
}

This is a companion discussion topic for the original entry at https://dgraph.io/docs/graphql/mutations/deep/

Deep update mutations are not supported in GraphQl. Also, there is no mutation named DeepAuthor.We should fix these docs.

1 Like

hmm, I don’t know why I still find myself trying to update nested data. Maybe because the docs still says it should, but it doesn’t. Now, to rebuild my mutation to update the nested data in sibling mutations instead of deep mutations.

yeah , docs are not updated yet. But a PR is already for it raised and will be merged soon.

Hi, Everyone! Updated docs for deep mutations are now available: https://dgraph.io/docs/master/graphql/mutations/deep/. These will be merged to the 20.11 docs branch soon. Thank you!