relay-utils
Version:
Utilities for working with Relay (modern) in general, and the Relay store in particular.
18 lines (14 loc) • 393 B
Flow
// @flow
import type { RecordProxy } from 'relay-runtime/store/RelayStoreTypes';
export function resolveNestedRecord(
rootRecord: RecordProxy,
path: Array<string>
): ?RecordProxy {
let node: ?RecordProxy = rootRecord;
for (let i = 0; i <= path.length - 1; i += 1) {
if (node) {
node = node.getLinkedRecord(path[i]);
}
}
return node !== rootRecord ? node : null;
}