UNPKG

nestjs-decorated-dataloaders

Version:

A module that helps you to create graphql dataloaders with decorators in Nest.js

31 lines 1 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.resolvePath = resolvePath; function resolvePath(entity, path) { if (!path || !entity) return undefined; // If the path is a function, call it with the entity if (typeof path === "function") { return path(entity); } // Otherwise, handle the string path as before let current = entity; const parts = path.split("."); for (const part of parts) { if (Array.isArray(current)) { const results = current.map((item) => item === null || item === void 0 ? void 0 : item[part]).filter((value) => value !== undefined); if (!results.length) { return undefined; } current = results; } else { if (current === undefined) { return undefined; } current = current[part]; } } return current; } //# sourceMappingURL=resolve-path.js.map