@graphql-mesh/fusion-runtime
Version:
Runtime for GraphQL Mesh Fusion Supergraph
34 lines (33 loc) • 1.62 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getExecutorForUnifiedGraph = getExecutorForUnifiedGraph;
exports.getSdkRequesterForUnifiedGraph = getSdkRequesterForUnifiedGraph;
const transport_common_1 = require("@graphql-mesh/transport-common");
const utils_1 = require("@graphql-mesh/utils");
const disposablestack_1 = require("@whatwg-node/disposablestack");
const unifiedGraphManager_js_1 = require("./unifiedGraphManager.js");
function getExecutorForUnifiedGraph(opts) {
const unifiedGraphManager = new unifiedGraphManager_js_1.UnifiedGraphManager(opts);
const unifiedGraphExecutor = function unifiedGraphExecutor(execReq) {
return (0, utils_1.mapMaybePromise)(unifiedGraphManager.getContext(execReq.context), context => {
return (0, utils_1.mapMaybePromise)(unifiedGraphManager.getUnifiedGraph(), unifiedGraph => (0, transport_common_1.createDefaultExecutor)(unifiedGraph)({
...execReq,
context,
}));
});
};
unifiedGraphExecutor[disposablestack_1.DisposableSymbols.asyncDispose] = function unifiedGraphExecutorDispose() {
return unifiedGraphManager[disposablestack_1.DisposableSymbols.asyncDispose]();
};
return unifiedGraphExecutor;
}
function getSdkRequesterForUnifiedGraph(opts) {
const unifiedGraphExecutor = getExecutorForUnifiedGraph(opts);
return function sdkRequester(document, variables, operationContext) {
return unifiedGraphExecutor({
document,
variables,
context: operationContext,
});
};
}