UNPKG

@pothos/plugin-dataloader

Version:

A Pothos plugin for attaching dataloader to object types

47 lines (46 loc) 1.86 kB
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; } import { ImplementableObjectRef } from '@pothos/core'; import { dataloaderGetter } from '../util.js'; import { LoadableObjectRef } from './object.js'; export class LoadableNodeRef extends LoadableObjectRef { constructor(builder, name, { id, loaderOptions, load, toKey, sort }) { super(name, dataloaderGetter(loaderOptions, load, toKey, sort)), _define_property(this, "parseId", void 0), _define_property(this, "builder", void 0); this.builder = builder; this.parseId = id.parse; } } export class ImplementableLoadableNodeRef extends 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 = 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