UNPKG

simple-graphql

Version:

The simple way to generates GraphQL schemas and Sequelize models from your models definition.

101 lines 4.12 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = (hooks, sgContext) => { const finalHooks = [...hooks].sort((p1, p2) => { const p1n = p1.priority || 0; const p2n = p2.priority || 0; if (p1n < p2n) { return 1; } else if (p1n > p2n) { return -1; } else { return 0; } }); const applyHooks = (target) => { let hookFunc = (target, invokeInfo, next) => next(); [...finalHooks].reverse().forEach((hook) => { var _a; const func = hookFunc; const hookTarget = Object.assign(Object.assign({}, target), { options: (_a = target.targetConfig.hookOptions) === null || _a === void 0 ? void 0 : _a[hook.name] }); if (hook.filter == null || hook.filter(hookTarget)) { hookFunc = (target, invokeInfo, next) => hook.hook(hookTarget, invokeInfo, func.bind(null, target, invokeInfo, next)); } }); return hookFunc; }; return { hookFieldResolve: (name, options) => { const target = { type: 'field', name: name, targetConfig: options }; const hookFunc = applyHooks(target); return (source, args, context, info) => hookFunc(target, { source: source, args: args, context: context, info: info, sgContext: sgContext }, () => options.resolve(source, args, context, info, sgContext)); }, hookQueryResolve: (name, options) => { const target = { type: 'query', name: name, targetConfig: options }; const hookFunc = applyHooks(target); return (source, args, context, info) => hookFunc(target, { source: source, args: args, context: context, info: info, sgContext: sgContext }, () => options.resolve(args, context, info, sgContext)); }, hookSubscriptionResolve: (name, options) => { const target = { type: 'subscription', name: name, targetConfig: options }; const hookFunc = applyHooks(target); return (source, args, context, info) => hookFunc(target, { source: source, args: args, context: context, info: info, sgContext: sgContext }, () => __awaiter(void 0, void 0, void 0, function* () { return options.subscribe(args, context, info, sgContext); })); }, hookMutationResolve: (name, options) => { const target = { type: 'mutation', name: name, targetConfig: options }; const hookFunc = applyHooks(target); return (source, args, context, info) => hookFunc(target, { source: source, args: args, context: context, info: info, sgContext: sgContext }, () => options.mutateAndGetPayload(args, context, info, sgContext)); } }; }; //# sourceMappingURL=buildResolverContext.js.map