@pothos/plugin-dataloader
Version:
A Pothos plugin for attaching dataloader to object types
38 lines (37 loc) • 1.42 kB
JavaScript
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, ObjectRef } from '@pothos/core';
import { dataloaderGetter } from '../util.js';
export class LoadableObjectRef extends ObjectRef {
constructor(name, getDataloader) {
super(name), _define_property(this, "getDataloader", void 0);
this.getDataloader = getDataloader;
}
}
export class ImplementableLoadableObjectRef extends ImplementableObjectRef {
constructor(builder, name, { loaderOptions, load, toKey, sort, cacheResolved }) {
super(builder, name), _define_property(this, "getDataloader", void 0), _define_property(this, "cacheResolved", void 0);
this.getDataloader = dataloaderGetter(loaderOptions, load, toKey, sort);
this.cacheResolved = typeof cacheResolved === "function" ? cacheResolved : cacheResolved && toKey;
this.builder.configStore.onTypeConfig(this, (config) => {
config.extensions = {
...config.extensions,
getDataloader: this.getDataloader,
cacheResolved: this.cacheResolved
};
});
}
}
//# sourceMappingURL=object.js.map