@giraphql/plugin-dataloader
Version:
A GiraphQL plugin for attaching dataloader to object types
23 lines • 984 B
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
const core_1 = require("@giraphql/core");
const util_1 = require("./util");
const _1 = require(".");
const fieldBuilderProto = core_1.RootFieldBuilder.prototype;
fieldBuilderProto.loadable = function loadable({ load, sort, loaderOptions, resolve, type, ...options }) {
const getLoader = (0, _1.dataloaderGetter)(loaderOptions, load, undefined, sort);
return this.field({
...options,
type,
// @ts-expect-error types don't match because this handles both lists and single objects
resolve: async (parent, args, context, info) => {
const ids = await resolve(parent, args, context, info);
const loader = getLoader(context);
if (Array.isArray(type)) {
return (0, util_1.rejectErrors)(loader.loadMany(ids));
}
return loader.load(ids);
},
});
};
//# sourceMappingURL=field-builder.js.map
;