Remove all groups from user in ACL via graphql

It seems if I want to change a user group in ACL via dgraph (not add to it) I have to make a query and then two mutations?

For example, if a user is attached to ACL group “guardians” and we want to change them to group “staff” we have to first query to find out what their existing group is, then make a mutation to delete that group from their user, and then a final mutation to add the group “staff”. Is that correct?

I tried doing remove: { groups: null }, but that does not work.

You can do this with a query and a mutation. The first query to know which groups the the user is a part of, and then a mutation to both set and remove the corresponding groups.

This mutation should work for you:

mutation ChangeUserGroups {
  updateUser(input: {
    filter: {name: {eq: "alice"}},
    set:    {groups: [{name: "staff"}]},
    remove: {groups: [{name: "guardians"}]}
  }) {
    user {
      name
      groups {
        name
      }
    }
  }
}

Of course, if you know the groups to remove from up front, then the initial query isn’t needed.

2 Likes