UNPKG

@graphql-mesh/fusion-runtime

Version:

Runtime for GraphQL Mesh Fusion Supergraph

30 lines (29 loc) 1.31 kB
import { createDefaultExecutor } from '@graphql-mesh/transport-common'; import { mapMaybePromise } from '@graphql-mesh/utils'; import { DisposableSymbols } from '@whatwg-node/disposablestack'; import { UnifiedGraphManager } from './unifiedGraphManager.js'; export function getExecutorForUnifiedGraph(opts) { const unifiedGraphManager = new UnifiedGraphManager(opts); const unifiedGraphExecutor = function unifiedGraphExecutor(execReq) { return mapMaybePromise(unifiedGraphManager.getContext(execReq.context), context => { return mapMaybePromise(unifiedGraphManager.getUnifiedGraph(), unifiedGraph => createDefaultExecutor(unifiedGraph)({ ...execReq, context, })); }); }; unifiedGraphExecutor[DisposableSymbols.asyncDispose] = function unifiedGraphExecutorDispose() { return unifiedGraphManager[DisposableSymbols.asyncDispose](); }; return unifiedGraphExecutor; } export function getSdkRequesterForUnifiedGraph(opts) { const unifiedGraphExecutor = getExecutorForUnifiedGraph(opts); return function sdkRequester(document, variables, operationContext) { return unifiedGraphExecutor({ document, variables, context: operationContext, }); }; }