I was following the instructions here and it seems like that I cannot update fields with the @id directive. Is that so or am I doing something wrong? I understand that when having the @id directive only, updating basically the ID does not make sense. In my case however, I have defined id: ID!andemail: String! @id and in this case it would be nice to be able update the email field.
Thanks! So if I got this right an @id field is not mutable but the functionality should have been included within 21.07. When will this be working or is there a workaround?
You can update the data using a DQL mutation. If you donāt have the uid mapped in GraphQL using ID then you can do an upsert using your field with @id.
type User {
username: String @id
isActive: Boolean
}
upsert {
query {
user as var(func: eq(User.username,"foo"))
}
mutation {
set {
uid(user) <User.username> "bar" .
}
}
}
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
This is still valid schema. But you have to use the DQL endpoint and syntax to update the email field at this time. You can have both an @id field and an ID field. In fact you can have multiple fields with @id but they all work as unique āindexesā not compound.
Right now in GraphQL upserts are for insert or update logic, but not update the @id field.
This updates all fields fine! Unfortunately, I ran into another problem What if I have
enum RoleType {
"ADMIN"
"MEMBER"
}
type Role {
id: ID!
type: RoleType!
}
type User {
id: ID!
email: String! @id
userName: String
role: Role
}
I can perform deep mutations with a GraphQL query but it is not clear to me how I do this with DQL? I have read this but I guess Iām using it wrong since I only get errors that my input type uid is a scalar⦠Could someone explain me what I have to do if I want to update User.role?
Maybe there was a misunderstanding: I do not want to update the Role but I want to reference it to another Role. Therefore, the GraphQL mutation was working nicely on User.role before.
and I get no errors but there is also no update on the User.role field. I I try with upsert I get an error message that there is a bad character somewhereā¦
I have tried to do the GraphQL mutation for all fields, except for email and do the email field with DQL. This works but this seems a bit of a really dirty hackā¦
Ah, sorry. This is not a deep mutation. You are just changing an edge of the parent node. So if the other role already exist then you will just need the id of the other role node.
Letās assume the role you want to add is 0x6 to the user with od 0x3. If you want to add a new one not existing you can also do that.
Since it is a one-to-one relationship you can do it all in a single mutation.
mutation changeRole {
updateUser(input: {
filter: { id: ["0x3"] }
set: {
role: {
id: "0x6"
}
}
}) {
user {
id
email
userName
role {
id
type
}
}
}
}
Thanks again for the reply. Originally I had the GraphQL mutation like you have suggested here. The problem was that I can not update the email field with GraphQL since it has the @id directive in the schema. You told me that this is only possible with DQL. Applying DQL works but unfortunately I do not know the right syntax to update the reference for role with DQL.
I have tried:
set {
"role": {
"id": ${input.roleId}
}
}
where I get the error that \"role\": { \"id\": 0x3d3aa4e71 } at line 2 column 7: Invalid character '{' inside mutation text". So this does not seem to work. Then Iāve tried
set {
<${input.userId}> <User.role.id> "${input.roleId}" .
}
which at least runs through without errors, updates all the other fields, but leaves role.id untouched.
I could obviously run the DQL mutation on email only and do the rest with a GraphQL mutation but this seems a bit hackyā¦