首页 > 解决方案 > 中继现代商店客户端中的排序连接

问题描述

我有一个突变,可以重新排序中继连接中的两条边。乐观地执行这种重新排序的正确方法是什么?我尝试了一种就地排序,例如:

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;
});

这似乎不起作用。我怀疑中继非常努力地不允许存储突变,除非通过其界面。我想我可以使用 ConnectionHandler 删除所有现有的边缘,然后以正确的顺序将它们全部添加回来,但这听起来很麻烦。有没有更好的办法?

标签: relaymodern

解决方案


RecordProxy.setLinkedRecords使这不那么糟糕:

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');

如果有人有更时尚的方式,仍然有点好奇。


推荐阅读