@graphql-tools/executor-yoga
Version:
A set of utils for faster development of GraphQL tools
38 lines (37 loc) • 1.29 kB
JavaScript
import { DisposableSymbols } from 'graphql-yoga';
import { useExecutor as useEnvelopExecutor, } from '@graphql-tools/executor-envelop';
export function useExecutor(executor, opts) {
let logWarn = opts?.logWarn || ((message) => console.warn(message));
const envelopPlugin = useEnvelopExecutor(executor, {
...opts,
logWarn(...args) {
return logWarn(...args);
},
});
let disposableSymbol;
if (executor[DisposableSymbols.asyncDispose]) {
disposableSymbol = DisposableSymbols.asyncDispose;
}
else if (executor[DisposableSymbols.dispose]) {
disposableSymbol = 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]();
},
};
}