UNPKG

@graphql-tools/executor-yoga

Version:

A set of utils for faster development of GraphQL tools

41 lines (40 loc) 1.45 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.useExecutor = useExecutor; const graphql_yoga_1 = require("graphql-yoga"); const executor_envelop_1 = require("@graphql-tools/executor-envelop"); function useExecutor(executor, opts) { let logWarn = opts?.logWarn || ((message) => console.warn(message)); const envelopPlugin = (0, executor_envelop_1.useExecutor)(executor, { ...opts, logWarn(...args) { return logWarn(...args); }, }); let disposableSymbol; if (executor[graphql_yoga_1.DisposableSymbols.asyncDispose]) { disposableSymbol = graphql_yoga_1.DisposableSymbols.asyncDispose; } else if (executor[graphql_yoga_1.DisposableSymbols.dispose]) { disposableSymbol = graphql_yoga_1.DisposableSymbols.dispose; } return { ...envelopPlugin, onYogaInit({ yoga }) { logWarn = (...args) => yoga.logger.warn(...args); }, onRequestParse({ serverContext }) { return { onRequestParseDone() { envelopPlugin.ensureSchema(serverContext); if (envelopPlugin.pluginCtx.schemaSetPromise$) { return envelopPlugin.pluginCtx.schemaSetPromise$; } }, }; }, [disposableSymbol]() { return executor[disposableSymbol](); }, }; }