@webundsoehne/nestjs-graphql-typeorm-dataloader
Version:
A library to utilize the graphql-dataloader with nestjs and typeorm.
51 lines (50 loc) • 2.02 kB
JavaScript
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
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 __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var data_loader_plugin_exports = {};
__export(data_loader_plugin_exports, {
ApolloServerDataLoaderPlugin: () => ApolloServerDataLoaderPlugin
});
module.exports = __toCommonJS(data_loader_plugin_exports);
var import_typedi = require("typedi");
var import_uuid = require("uuid");
var import_context = require("../constants/context.constants");
class ApolloServerDataLoaderPlugin {
constructor(options) {
this.options = options;
}
async requestDidStart() {
const options = this.options;
return {
didResolveSource: async (requestContext) => {
requestContext.context[import_context.DATA_LOADER_CONTEXT_KEY] = {
requestId: (0, import_uuid.v4)(),
typeormGetConnection: options?.typeormGetConnection
};
},
willSendResponse: async (requestContext) => {
import_typedi.Container.reset(requestContext.context[import_context.DATA_LOADER_CONTEXT_KEY].requestId);
}
};
}
}
__name(ApolloServerDataLoaderPlugin, "ApolloServerDataLoaderPlugin");
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
ApolloServerDataLoaderPlugin
});