0

I have a mutation that reorders two edges in a relay connection. What is the right way to perform this reordering optimistically? I've tried an in-place sort like:

const conn = ConnectionHandler.getConnection(pathway, 'PathwayGraph_actions');
const edges = conn.getLinkedRecords('edges');

edges.sort((a, b) => {
    const laneA = a.getLinkedRecord('node').getValue('laneNumber');
    const laneB = b.getLinkedRecord('node').getValue('laneNumber');

    return laneA - laneB;
});

This doesn't seem to work. I suspect relay tries pretty hard to not allow store mutations except through its interface. I suppose I could use ConnectionHandler to delete all the existing edges, and then add them all back in the proper order, but that sounds quite cumbersome. Is there a better way?

Rob Allsopp
  • 3,309
  • 5
  • 34
  • 53

1 Answers1

1

RecordProxy.setLinkedRecords made this not so awful:

edges.sort((a, b) => {
    const laneA = a.getLinkedRecord('node').getValue('laneNumber');
    const laneB = b.getLinkedRecord('node').getValue('laneNumber');

    return laneA - laneB;
});

conn.setLinkedRecords(edges, 'edges');

Still a bit curious if anyone has a sleeker way.

Rob Allsopp
  • 3,309
  • 5
  • 34
  • 53