Relay: How To Get Connection From Store When Used With Order_by Or Other Params?
I have a question regarding ConnectionHandler used in updater. I am reading the example and found
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');
So the connections could accept {orderby: 'firstname'}. What is my orderby field can take in either firstname or secondname or fullname? So if I am sorting by firstname, I should update the connection with orderby = firstname and when I am sorting by lastname, I should get connection by orderby = lastname ... How do I know which orderby I am under or could I just update the "current one"?
Answer
@Junchao, I see that you took this example from the relay docs right? This orderby
that is passed, you are not actually telling Relay to order the edges for you by firstname
, but this parameter is the filters
one, which is used to identify the connection like said on the comment.
If you specified a filter
on your query, you also must pass the filter on getConnection
, otherwise, you won't find it.
:)
Related Questions
- → Import statement and Babel
- → should I choose reactjs+f7 or f7+vue.js?
- → Uncaught TypeError: Cannot read property '__SECRET_DOM_DO_NOT_USE_OR_YOU_WILL_BE_FIRED' of undefined
- → .tsx webpack compile fails: Unexpected token <
- → React-router: Passing props to children
- → ListView.DataSource looping data for React Native
- → React Native with visual studio 2015 IDE
- → Can't test submit handler in React component
- → React + Flux - How to avoid global variable
- → Webpack, React & Babel, not rendering DOM
- → How do I determine if a new ReactJS session and/or Browser session has started?
- → Alt @decorators in React-Native
- → How to dynamically add class to parent div of focused input field?