GraphQL Creating new User-Realm-Permission



I’m trying to create user, realm and add permission to created user to created realm.
I have running Realm Object Server version 3.17.1 in docker.

If I get access token to __admin realm and try to execute graphql mutations on http://localhost:9080/graphql/__admin

  1. create account
{"query":"mutation addAccount($accountInput: AccountInput) { 
     addAccount(input: $accountInput) {provider, providerId}}",
  1. create user
{"query":"mutation addUser($userInput: UserInput) {
      addUser(input: $userInput) {userId, isAdmin, accounts{provider, providerId}, metadata{key, value}, status }}",
  1. create realm
{"query":"mutation addRealmFile($realmFileInput: RealmFileInput) { 
      addRealmFile(input: $realmFileInput) {path, realmType, syncLabel, owner{userId, isAdmin}, createdAt, lastVacuumed }}",
  1. add permission
{"query":"mutation addPermission($permissionInput: PermissionInput) { 
     addPermission(input: $permissionInput) {user{userId, isAdmin}, realmFile{path, realmType, syncLabel, createdAt}, mayRead, mayWrite, mayManage, updatedAt}}",

ends with error Attempting to create an object of type ‘User’ with an existing primary key value ‘‘test’’.

How can be new user with permission to newly created realm created? How the procedure looks like.


@ladislav.kaiser7931 Wow you definitely should not be editing the __admin realm if possible - this could easily bork your system if not done properly which is why we hide it and provide public APIs which under the hood edit the __admin realm in a safe way.

I would recommend implementing an admin node-js app that calls our well known Realm.Sync.User.login() and APIs to implement what you are describing.