it('creates the edges array if it does not exist', () => { connection = proxy.create('connection', 'FriendsConnection'); RelayConnectionHandler.insertEdgeBefore(connection, newEdge); expect(sinkData.connection).toEqual({ [ID_KEY]: 'connection', [TYPENAME_KEY]: 'FriendsConnection', edges: { [REFS_KEY]: ['newedge'], }, }); });
it('inserts the edge before the edge with the given cursor', () => { RelayConnectionHandler.insertEdgeBefore(connection, newEdge, 'cursor:2'); expect(sinkData[connectionID]).toEqual({ [ID_KEY]: connectionID, [TYPENAME_KEY]: 'FriendsConnection', edges: { [REFS_KEY]: [ 'client:4:__ConnectionQuery_friends_connection{"orderby":["first name"]}:edges:0', 'newedge', 'client:4:__ConnectionQuery_friends_connection{"orderby":["first name"]}:edges:1', ], }, }); });
it('prepends the edge if no cursor is supplied', () => { RelayConnectionHandler.insertEdgeBefore(connection, newEdge); expect(sinkData[connectionID]).toEqual({ [ID_KEY]: connectionID, [TYPENAME_KEY]: 'FriendsConnection', edges: { [REFS_KEY]: [ 'newedge', 'client:4:__ConnectionQuery_friends_connection{"orderby":["first name"]}:edges:0', 'client:4:__ConnectionQuery_friends_connection{"orderby":["first name"]}:edges:1', ], }, }); });
updater = (store: RecordSourceSelectorProxy, data: ?SelectorData) => { const parent = store.get(parentID); if (parent) { const payload = store.getRootField(rootField); if (!payload) { return; } const newEdge = payload.getLinkedRecord(edgeName); for (const info of connectionInfo) { if (newEdge) { const connection = RelayConnectionHandler.getConnection( parent, info.key, info.filters, ); if (!connection) { return; } switch (info.rangeBehavior) { case 'append': RelayConnectionHandler.insertEdgeAfter(connection, newEdge); break; case 'ignore': // Do nothing break; case 'prepend': RelayConnectionHandler.insertEdgeBefore(connection, newEdge); break; default: warning( false, 'setRelayModernMutationConfigs: RANGE_ADD range behavior ' + `'${info.rangeBehavior}' will not work as expected in RelayModern, ` + "supported range behaviors are 'append', 'prepend', and " + "'ignore'", ); break; } } } } };