Hi, I ran into a problem which is really making me crazy right now…
Let’s assume the following setup:
type User {
id: ID!
role: Role!
tenantOf: [Organisation!]!
}
type Role {
id: ID!
type: RoleType!
}
enum RoleType {
"ADMIN"
"MEMBER"
}
type Organisation {
id: ID!
orgId: String! @id @search(by: [hash])
tenants: [User!] @hasInverse(field: tenantOf)
}
A typical update mutation would then be:
mutation Update( $id: [ID!], $roleId: ID!, $orgs: [OrganisationRef!] ) {
updateUser( input: {
filter: { id: $id },
set: {
tenantOf: $orgs
role: {
id: $roleId
}
}
}
}
where the variable $orgs
has the following form:
orgs = [
{ orgId: "some_id_1" },
{ orgId: "some_id_2" }
]
If I run this mutation everything works fine and I can keep adding organisations to tenantOf
. Unfortunately, if I want to remove one of the organisation references for the user, eg. by submitting
orgs = [
{ orgId: "some_id_1" }
]
it does not work - it keeps what ever was already in the array. I’ve researched a bit and the closest I could find was this post here, where using remove
has been suggested within the mutation. So I have changed my mutation to
mutation Update( $id: [ID!], $roleId: ID!, $addOrgs: [OrganisationRef!], $removeOrgs: [OrganisationRef!] ) {
updateUser( input: {
filter: { id: $id },
remove: { tenantOf: $removeOrgs },
set: {
tenantOf: $orgs
role: {
id: $roleId
}
}
}
}
where I have set the organisation arrays to
addOrgs = [
{ orgId: "some_id_1" }
]
removeOrgs = [
{ orgId: "some_id_1" },
{ orgId: "some_id_2" }
]
Which is basically removing the old references and setting the new references - so I thought. Unfortunately, if I do so the field tenantOf
gets completely removed from the user object! Am I doing this right? Thanks, any help appreciated!