UNPKG

@pothos/plugin-dataloader

Version:

A Pothos plugin for attaching dataloader to object types

64 lines (63 loc) 2.29 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); function _export(target, all) { for(var name in all)Object.defineProperty(target, name, { enumerable: true, get: all[name] }); } _export(exports, { ImplementableLoadableNodeRef: function() { return ImplementableLoadableNodeRef; }, LoadableNodeRef: function() { return LoadableNodeRef; } }); const _core = require("@pothos/core"); const _util = require("../util"); const _object = require("./object"); function _define_property(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } class LoadableNodeRef extends _object.LoadableObjectRef { constructor(builder, name, { id, loaderOptions, load, toKey, sort }){ super(name, (0, _util.dataloaderGetter)(loaderOptions, load, toKey, sort)), _define_property(this, "parseId", void 0), _define_property(this, "builder", void 0); this.builder = builder; this.parseId = id.parse; } } class ImplementableLoadableNodeRef extends _core.ImplementableObjectRef { constructor(builder, name, { id, loaderOptions, load, toKey, sort, cacheResolved }){ super(builder, name), _define_property(this, "parseId", void 0), _define_property(this, "getDataloader", void 0), _define_property(this, "cacheResolved", void 0); this.parseId = id.parse; this.builder = builder; this.getDataloader = (0, _util.dataloaderGetter)(loaderOptions, load, toKey, sort); this.cacheResolved = typeof cacheResolved === 'function' ? cacheResolved : cacheResolved && toKey; this.builder.nodeRef(this, { id, loadManyWithoutCache: (ids, context)=>this.getDataloader(context).loadMany(ids) }); this.updateConfig((config)=>({ ...config, extensions: { ...config.extensions, getDataloader: this.getDataloader, cacheResolved: this.cacheResolved } })); } } //# sourceMappingURL=node.js.map