中继:与 order_by 或其他参数一起使用时如何从商店获取连接?

Relay: how to get connection from store when used with order_by or other params?

我对更新程序中使用的 ConnectionHandler 有疑问。我正在阅读示例并发现

import {ConnectionHandler} from 'relay-runtime';

// The `friends` connection record can be accessed with:
const user = store.get(userID);
const friends = RelayConnectionHandler.getConnection(
 user,                        // parent record
 'FriendsFragment_friends'    // connection key
 {orderby: 'firstname'}       // 'filters' that is used to identify the connection
);
// Access fields on the connection:
const edges = friends.getLinkedRecords('edges');

因此连接可以接受 {orderby: 'firstname'}。什么是我的 orderby 字段可以接受名字或第二名或全名?因此,如果我按名字排序,我应该使用 orderby = firstname 更新连接,当我按姓氏排序时,我应该按 orderby = lastname 获取连接 ... 我怎么知道我在哪个 orderby 下,或者我可以只更新 "current one"?

@Junchao,我看你这个例子是从relay docs拿来的吧?传递的这个 orderby ,你实际上并不是告诉 Relay 按 firstname 为你排序边缘,而是这个参数是 filters 一个,用于识别连接,就像说的那样在评论上。 如果您在查询中指定了 filter,则还必须通过 getConnection 上的过滤器,否则,您将找不到它。

:)