UNPKG

@pothos/plugin-tracing

Version:

A Pothos plugin for tracing and logging resolver invocations

107 lines (106 loc) 3.8 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); function _export(target, all) { for(var name in all)Object.defineProperty(target, name, { enumerable: true, get: Object.getOwnPropertyDescriptor(all, name).get }); } _export(exports, { get PothosTracingPlugin () { return PothosTracingPlugin; }, get default () { return _default; } }); require("./global-types"); const _core = /*#__PURE__*/ _interop_require_wildcard(require("@pothos/core")); _export_star(require("./types"), exports); _export_star(require("./util"), exports); function _export_star(from, to) { Object.keys(from).forEach(function(k) { if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) { Object.defineProperty(to, k, { enumerable: true, get: function() { return from[k]; } }); } }); return from; } function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } function _interop_require_wildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = { __proto__: null }; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for(var key in obj){ if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } const pluginName = 'tracing'; const _default = pluginName; class PothosTracingPlugin extends _core.BasePlugin { wrapResolve(resolver, fieldConfig) { if (!this.builder.options.tracing) { return resolver; } const { wrap, default: defaultConfig } = this.builder.options.tracing; var _fieldConfig_pothosOptions_tracing; const tracingValue = (_fieldConfig_pothosOptions_tracing = fieldConfig.pothosOptions.tracing) !== null && _fieldConfig_pothosOptions_tracing !== void 0 ? _fieldConfig_pothosOptions_tracing : typeof defaultConfig === 'function' ? defaultConfig(fieldConfig) : defaultConfig; return wrapResolver(fieldConfig, tracingValue, wrap, resolver); } } function wrapResolver(fieldConfig, tracingOptions, wrap, resolver) { if (tracingOptions === false || tracingOptions === null) { return resolver; } if (typeof tracingOptions === 'function') { return (source, args, ctx, info)=>{ const options = tracingOptions(source, args, ctx, info); if (options === null || options === false) { return resolver(source, args, ctx, info); } return wrap(resolver, options, fieldConfig)(source, args, ctx, info); }; } return wrap(resolver, tracingOptions, fieldConfig); } _core.default.registerPlugin(pluginName, PothosTracingPlugin); //# sourceMappingURL=index.js.map