UNPKG

@graphql-mesh/fusion-runtime

Version:

Runtime for GraphQL Mesh Fusion Supergraph

104 lines (103 loc) 5.65 kB
import { DocumentNode, ExecutionResult, GraphQLSchema } from 'graphql'; import type { Plugin } from 'graphql-yoga'; import { ExecutableOperationPlan } from '@graphql-mesh/fusion-execution'; import { Transport, TransportBaseContext, TransportEntry, TransportExecutorFactoryFn, TransportExecutorFactoryOpts } from '@graphql-mesh/transport-common'; import { ExecutionRequest, Executor, IResolvers } from '@graphql-tools/utils'; export { Transport, TransportEntry, TransportExecutorFactoryFn, TransportExecutorFactoryOpts }; export declare function getSubgraphTransportMapFromFusiongraph(fusiongraph: GraphQLSchema): Record<string, TransportEntry>; export declare const getMemoizedExecutionPlanForOperation: (fusiongraph: GraphQLSchema, document: DocumentNode, operationName?: string, _random?: number) => ExecutableOperationPlan; export type TransportsOption = { [TTransportKind in string]: Transport<TTransportKind>; } | (<TTransportKind extends string>(transportKind: TTransportKind) => Promise<Transport<TTransportKind>> | Transport<TTransportKind>); interface GetExecutorForFusiongraphOpts extends TransportBaseContext { fusiongraph: GraphQLSchema; transports?: TransportsOption; plugins?: FusiongraphPlugin[]; } export declare function defaultTransportsOption(transportKind: string): Promise<any>; export declare function createTransportGetter(transports: TransportsOption): <TTransportKind extends string>(transportKind: TTransportKind) => Transport<TTransportKind> | Promise<Transport<TTransportKind>>; export declare function getTransportExecutor(transportGetter: ReturnType<typeof createTransportGetter>, transportContext: TransportExecutorFactoryOpts): Executor | Promise<Executor>; export declare function getExecutorForFusiongraph({ fusiongraph, transports, plugins, ...transportBaseContext }: GetExecutorForFusiongraphOpts): { fusiongraphExecutor: (execReq: ExecutionRequest) => { data: any; errors: import("graphql").GraphQLError[]; extensions: { executionPlan: { resolverOperationNodes: import("@graphql-mesh/fusion-execution").SerializedResolverOperationNode[]; resolverDependencyFieldMap: { [k: string]: import("@graphql-mesh/fusion-execution").SerializedResolverOperationNode[]; }; }; outputVariables: { [k: string]: any; }; }; } | Promise<{ data: any; errors: import("graphql").GraphQLError[]; extensions: { executionPlan: { resolverOperationNodes: import("@graphql-mesh/fusion-execution").SerializedResolverOperationNode[]; resolverDependencyFieldMap: { [k: string]: import("@graphql-mesh/fusion-execution").SerializedResolverOperationNode[]; }; }; outputVariables: { [k: string]: any; }; }; }> | AsyncIterableIterator<{ data: any; errors: import("graphql").GraphQLError[]; extensions: { executionPlan: { resolverOperationNodes: import("@graphql-mesh/fusion-execution").SerializedResolverOperationNode[]; resolverDependencyFieldMap: { [k: string]: import("@graphql-mesh/fusion-execution").SerializedResolverOperationNode[]; }; }; outputVariables: { [k: string]: any; }; }; }> | { data: any; }; transportEntryMap: Record<string, TransportEntry>; onSubgraphExecute: (subgraphName: string, document: DocumentNode, variables: any, context: any) => import("@graphql-tools/utils").MaybePromise<import("@graphql-tools/utils").MaybeAsyncIterable<import("@graphql-tools/utils").ExecutionResult<any, any>>>; }; export interface PlanCache { get(documentStr: string): Promise<ExecutableOperationPlan> | ExecutableOperationPlan; set(documentStr: string, plan: ExecutableOperationPlan): Promise<any> | any; } export interface YogaFusiongraphPluginOptions<TServerContext, TUserContext> { getFusiongraph(baseCtx: TransportBaseContext): GraphQLSchema | DocumentNode | string | Promise<GraphQLSchema | string | DocumentNode>; transports?: TransportsOption; planCache?: PlanCache; polling?: number; additionalResolvers?: IResolvers<unknown, TServerContext & TUserContext> | IResolvers<unknown, TServerContext & TUserContext>[]; transportBaseContext?: TransportBaseContext; } export declare function useFusiongraph<TServerContext, TUserContext>({ getFusiongraph, transports, additionalResolvers, polling, transportBaseContext, }: YogaFusiongraphPluginOptions<TServerContext, TUserContext>): Plugin<{}, TServerContext, TUserContext> & { invalidateUnifiedGraph(): void; }; export interface FusiongraphPlugin { onSubgraphExecute?: OnSubgraphExecuteHook; } export type OnSubgraphExecuteHook = (payload: OnFusiongraphExecutePayload) => Promise<OnSubgraphExecuteDoneHook> | OnSubgraphExecuteDoneHook; export interface OnFusiongraphExecutePayload { fusiongraph: GraphQLSchema; subgraphName: string; transportKind: string; transportLocation: string; transportHeaders: Record<string, string>; transportOptions: any; executionRequest: ExecutionRequest; executor: Executor; setExecutor(executor: Executor): void; } export interface OnSubgraphExecuteDonePayload { result: ExecutionResult; setResult(result: ExecutionResult): void; } export type OnSubgraphExecuteDoneHook = (payload: OnSubgraphExecuteDonePayload) => Promise<void> | void;