Data doesn't update

Hi,

I have this data in my db:

"branch": [
        {
          "versions": [
            {
              "wayOfCreation": "New_Branch",
              "code": "1.0",
              "orkId": "0x13882-master-1.0"
            },
            {
              "wayOfCreation": "New_Version",
              "code": "1.1",
              "orkId": "0x13882-master-1.1"
            }
          ]
        }
      ]

I try to update the data using deep update with the following mutation:

mutation MyMutation {
  updateBranch(input: {filter: {orkId: {eq: "0x13882-master"}}, set: {versions: [{orkId: "0x13882-master-1.0", code: "1.2"}, {orkId: "0x13882-master-1.1", wayOfCreation: Publish}]}}) {
    branch {
      versions {
        wayOfCreation
        code
        orkId
      }
    }
  }
}

but the result is:

{
  "data": {
    "updateBranch": {
      "branch": [
        {
          "versions": [
            {
              "wayOfCreation": "New_Branch",
              "code": "1.0",
              "orkId": "0x13882-master-1.0"
            },
            {
              "wayOfCreation": "New_Version",
              "code": "1.1",
              "orkId": "0x13882-master-1.1"
            }
          ]
        }
      ]
    }
  },

Nothing was changed
I tried to follow the example in the docs about the deep update

Hi @spinelsun, can you please share the schema?

Hi @anand

sure:

type Branch {
  orkId: String! @search(by: [hash]) @id
  changeMark: String!
  name: String! @search(by: [exact, regexp])
  versions: [Version!]!
  checkedOutFrom: Version @hasInverse(field: checkouts)
  in: Repository! @hasInverse(field: branches)
  createdAt: DateTime!
  createdBy: User!
}

type Version {
  orkId: String! @search(by: [hash]) @id
  code: String! @search(by: [regexp, hash])
  vid: String!
  gitCommit: String @search(by: [hash])
  next: Version
  previous: Version @hasInverse(field: next)
  ofBranch: Branch! @hasInverse(field: versions)
  publishedFrom: Version @hasInverse(field: publications)
  publications: [Version!]
  checkouts: [Branch!]
  artifacts: [IArtifact!] @hasInverse(field: inVersion)
  createdAt: DateTime!
  lastModified: DateTime
  createdBy: User!
  wayOfCreation: CreationType!
}

Thanks @spinelsun
Can you please query for all the versions of branch 0x13882-master and share with us?

query MyQuery {
  getBranch(orkId: "0x13882-master") {
    createdBy
    orkId
    versions {
       wayOfCreation
        code
        orkId
    }
  }
}

@anand here is the result

Hi @spinelsun
Deep mutations do not alter linked objects. In this case, versions will have to be updated via updateVersion API. We cannot alter existing versions using the updateBranch.

We are updating the documentation to clearly convey this aspect.

1 Like

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!

1 Like

I just now read through the deep mutation docs and even though I at first was disappointed that I can not fire deep mutations out of the box, looking from an recursive standpoint this makes totally sense, so thank you for educating me.

On another hand I found the update of list items confusing, so maybe this is a bug or I also need education here :smiley:

For convenience lets take the data from above.
Branch has different verisons. Now I want to overwrite my branch and set version to zero or even just one version.
What I experienced here is that no change is processed, which I find weird, as the versions list belongs to the main object, thus no deep mutation should effect here.
So my quesiton is, is this intentional or a bug?

mutation MyMutation {
  updateBranch(input: $input) {
    branch {
      versions {
        wayOfCreation
        code
        orkId
      }
    }
  }
}
{
	"input": {
		"filter": {
			"orkId": {
				"eq": "0x13882-master"
			}
		},
		"set": {
			"versions": []
		}
	}
}