relay-utils
Version:
Utilities for working with Relay (modern) in general, and the Relay store in particular.
37 lines (28 loc) • 1.03 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.createAndAddEdgeToConnections = createAndAddEdgeToConnections;
var _relayRuntime = require("relay-runtime");
function createAndAddEdgeToConnections(store, config) {
var node = config.node;
config.connections.forEach(function (connectionConfig) {
var connectionOwner = store.get(connectionConfig.parentID);
if (!connectionOwner) {
return;
}
var connection = _relayRuntime.ConnectionHandler.getConnection(connectionOwner, connectionConfig.key, connectionConfig.filters);
if (!connection) {
if (__DEV__) {
console.warn('Could not find connection.');
}
return;
}
var edge = _relayRuntime.ConnectionHandler.createEdge(store, connection, node, config.edgeName);
if (config.insertAt === 'START') {
_relayRuntime.ConnectionHandler.insertEdgeBefore(connection, edge);
} else {
_relayRuntime.ConnectionHandler.insertEdgeAfter(connection, edge);
}
});
}