Can I update fields with the @id directive?

Hey @amaster507!

Sorry for answering super late on this topic, I got dumped with work in the last couple of days…

First of all, thank you so much for pushing me into the right direction with this issue! Unfortunately, I still do not fully understand what I have to do. I was reading this post and if I understand right then I should be able to do something like:

type User {
  email: String! @id
  userName: String
}

According to the post, Dgraph should generate an update mutation, which looks something like

updateUser(input: [UpdateUserInput!]!, upsert: Boolean): UpdateUserPayload

and I should be able to update the email field by

mutation($email: String, $id: ID) {
  updateUser(input:{ filter: { id: $id }, set: { email: $email } }, upsert: true) {
    numUids
  }
}

The post states

The IDs must be external IDs, defined using the @id directive in the schema.

which I guess means that I am not allowed to have an extra ID field in my User type, right? To clarify, the type

type User {
  id: ID!
  email: String! @id
  userName: String
}

is not valid if I want to use upsert?
I’m asking because my updateUser mutation (with the second type User), has no upsert defined!

1 Like