@coderich/autograph 0.13.47 → 0.13.48
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/schema/Schema.js +8 -4
package/package.json
CHANGED
package/src/schema/Schema.js
CHANGED
|
@@ -527,11 +527,15 @@ module.exports = class Schema {
|
|
|
527
527
|
});
|
|
528
528
|
|
|
529
529
|
// Helper methods
|
|
530
|
+
const resolvePathCache = {};
|
|
530
531
|
this.#schema.resolvePath = (path, prop = 'key') => {
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
532
|
+
resolvePathCache[path] ??= (() => {
|
|
533
|
+
const [modelKey, ...fieldKeys] = path.split('.');
|
|
534
|
+
const $model = Object.values(this.#schema.models).find(el => el[prop] === modelKey);
|
|
535
|
+
if (!$model || !fieldKeys.length) return $model;
|
|
536
|
+
return fieldKeys.reduce((parent, key) => Object.values(parent.fields || parent.model.fields).find(el => el[prop] === key) || parent, $model);
|
|
537
|
+
})();
|
|
538
|
+
return resolvePathCache[path];
|
|
535
539
|
};
|
|
536
540
|
|
|
537
541
|
// Mutate typeDefs
|