UNPKG

@pothos/core

Version:

Pothos (formerly GiraphQL) is a plugin based schema builder for creating code-first GraphQL schemas in typescript

75 lines (74 loc) 3.14 kB
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 { BasePlugin } from './plugin.js'; export class MergedPlugins extends BasePlugin { onTypeConfig(typeConfig) { return this.plugins.reduceRight((config, plugin) => config === null ? config : plugin.onTypeConfig(config), typeConfig); } onInputFieldConfig(fieldConfig) { return this.plugins.reduceRight((config, plugin) => config === null ? config : plugin.onInputFieldConfig(config), fieldConfig); } onOutputFieldConfig(fieldConfig) { return this.plugins.reduceRight((config, plugin) => config === null ? config : plugin.onOutputFieldConfig(config), fieldConfig); } onEnumValueConfig(valueConfig) { return this.plugins.reduceRight((config, plugin) => config === null ? config : plugin.onEnumValueConfig(config), valueConfig); } beforeBuild() { for (const plugin of this.plugins) { plugin.beforeBuild(); } } afterBuild(schema) { return this.plugins.reduceRight((nextSchema, plugin) => plugin.afterBuild(nextSchema), schema); } wrapResolve(resolve, fieldConfig) { const wrapped = this.plugins.reduceRight((nextResolve, plugin) => plugin.wrapResolve(nextResolve, fieldConfig), resolve); if (fieldConfig.argMappers.length) { const argMappers = fieldConfig.argMappers; return (parent, args, context, info) => { const mappedArgs = argMappers.reduce((acc, argMapper) => { return argMapper(acc, context, info); }, args); return wrapped(parent, mappedArgs, context, info); }; } return wrapped; } wrapSubscribe(subscribe, fieldConfig) { const wrapped = this.plugins.reduceRight((nextSubscribe, plugin) => plugin.wrapSubscribe(nextSubscribe, fieldConfig), subscribe); if (!wrapped || !fieldConfig.argMappers.length) { return wrapped; } const argMappers = fieldConfig.argMappers; return (parent, args, context, info) => { const mappedArgs = argMappers.reduce((acc, argMapper) => { return argMapper(acc, context, info); }, args); return wrapped(parent, mappedArgs, context, info); }; } wrapResolveType(resolveType, typeConfig) { return this.plugins.reduceRight((nextResolveType, plugin) => plugin.wrapResolveType(nextResolveType, typeConfig), resolveType); } wrapIsTypeOf(isTypeOf, typeConfig) { return this.plugins.reduceRight((nextResolveType, plugin) => plugin.wrapIsTypeOf(nextResolveType, typeConfig), isTypeOf); } constructor(buildCache, plugins) { super(buildCache, "PothosMergedPlugin"), _define_property(this, "plugins", void 0); this.plugins = plugins; } } //# sourceMappingURL=merge-plugins.js.map