I’m assuming this may be what I need, but would li...
# orm-help
i
I’m assuming this may be what I need, but would like to verify if possible 🙂
n
from what you described, this sounds like what you need, but your situation is not entirely clear to me.
i
@nilan I ended up fetching the entity i wanted to update, diff-ing the fields that had relations I wanted to update, and disconnecting any that were not in the incoming array to update the particular field.
Copy code
const { id, values, read, write, name } = args;

  const current = await ctx.db.query.field(
    { where: { id } },
    "{ id read { type } write { type } }"
  );

  const connect = {
    read: difference(read, current.read.map(r => r.type)).map(type => ({ type })),
    write: difference(write, current.write.map(r => r.type)).map(type => ({ type }))
  };

  const disconnect = {
    read: difference(current.read.map(r => r.type), read).map(type => ({ type })),
    write: difference(current.write.map(r => r.type), write).map(type => ({ type }))
  };

  const field = await ctx.db.mutation.updateField({
    where: {
      id
    },
    data: {
      name,
      values: { set: values },
      read: {
        connect: connect.read,
        disconnect: disconnect.read
      },
      write: {
        connect: connect.write,
        disconnect: disconnect.write
      }
    }
  });
A little heavier than I’d like, but I understand that support for lots of nested mutation types are incoming in the future and this will work in the time being.
💯 1