To remember a connection, run RangeBehaviors.remember in relay.prepareVariables with a name, the connection arguments and an optional rangeBehavior operation:
prepareVariables(variables) {
var { startDate, endDate } = variables;
RangeBehaviors.remember('items', { startDate, endDate }, 'prepend'); // append if not specified
return variables;
}To populate rangeBehaviors in a RANGE_ADD mutation, run RangeBehaviors.get. The callback will run for every remembered connection.
getConfigs() {
var rangeBehaviors = RangeBehaviors.get('items', ({startDate, endDate}) => {
return dateIsBetween(this.props.date, startDate, endDate);
}
);
return [{
type: 'RANGE_ADD',
parentName: 'viewer',
parentID: this.props.viewer.id,
connectionName: 'items',
edgeName: 'itemEdge',
rangeBehaviors
}];
}Returning true in the callback will result in a rangeBehavior with the value (append/prepend) that was specified in RangeBehaviors.remember. Returning false will give the rangeBehavior the value of an empty string, in order to tell relay that nothing has to be done. You can also return append/prepend directly in the callback in order to override the default.