UNPKG

@webundsoehne/nestjs-graphql-typeorm-dataloader

Version:

A library to utilize the graphql-dataloader with nestjs and typeorm.

48 lines (47 loc) 2.29 kB
var __create = Object.create; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __getProtoOf = Object.getPrototypeOf; var __hasOwnProp = Object.prototype.hasOwnProperty; var __name = (target, value) => __defProp(target, "name", { value, configurable: true }); var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod )); var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); var callback_handler_handler_exports = {}; __export(callback_handler_handler_exports, { handler: () => handler }); module.exports = __toCommonJS(callback_handler_handler_exports); var import_typedi = __toESM(require("typedi")); var import_context = require("../constants/context.constants"); async function handler(context, relation, columns, newDataloader, callback) { if (context[import_context.DATA_LOADER_CONTEXT_KEY].typeormGetConnection == null) { throw new Error("Typeorm connection function is not available."); } const serviceId = `${import_context.DATA_LOADER_CONTEXT_KEY}#${relation.entityMetadata.tableName}#${relation.propertyName}`; const container = import_typedi.default.of(context[import_context.DATA_LOADER_CONTEXT_KEY].requestId); if (!container.has(serviceId)) { container.set(serviceId, newDataloader(context[import_context.DATA_LOADER_CONTEXT_KEY].typeormGetConnection())); } return callback(container.get(serviceId), columns); } __name(handler, "handler"); // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { handler });