@graphql-mesh/fusion-runtime
Version:
Runtime for GraphQL Mesh Fusion Supergraph
134 lines (133 loc) • 7.33 kB
TypeScript
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, type Maybe, type MaybePromise } 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 | DocumentNode | string;
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): MaybePromise<Executor>;
export declare function getOnSubgraphExecute({ getFusiongraph, plugins, transports, transportBaseContext, transportEntryMap, }: {
getFusiongraph: () => GraphQLSchema;
plugins?: FusiongraphPlugin[];
transports?: TransportsOption;
transportBaseContext?: TransportBaseContext;
transportEntryMap?: Record<string, TransportEntry>;
}): (subgraphName: string, document: DocumentNode, variables: any, context: any) => MaybePromise<import("@graphql-tools/utils").MaybeAsyncIterable<import("@graphql-tools/utils").ExecutionResult<any, any>>>;
export declare function getExecutorForFusiongraph({ fusiongraph: fusiongraphInput, 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;
};
};
} | 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;
};
};
}> | 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) => 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 FusiongraphPluginOptions<TContext> {
getFusiongraph(baseCtx: TransportBaseContext): GraphQLSchema | DocumentNode | string | Promise<GraphQLSchema | string | DocumentNode>;
transports?: TransportsOption;
planCache?: PlanCache;
polling?: number;
additionalResolvers?: IResolvers<unknown, TContext> | IResolvers<unknown, TContext>[];
transportBaseContext?: TransportBaseContext;
readinessCheckEndpoint?: string;
}
export declare function useFusiongraph<TContext extends Record<string, any> = Record<string, any>>({ getFusiongraph, transports, additionalResolvers, polling, transportBaseContext, readinessCheckEndpoint, }: FusiongraphPluginOptions<TContext>): Plugin<TContext> & {
invalidateUnifiedGraph(): void;
};
export interface FusiongraphPlugin {
onSubgraphExecute?: OnSubgraphExecuteHook;
}
export type OnSubgraphExecuteHook = (payload: OnFusiongraphExecutePayload) => Promise<Maybe<OnSubgraphExecuteDoneHook | void>> | Maybe<OnSubgraphExecuteDoneHook | void>;
export interface OnFusiongraphExecutePayload {
fusiongraph: GraphQLSchema;
subgraphName: string;
transportEntry?: TransportEntry;
executionRequest: ExecutionRequest;
setExecutionRequest(executionRequest: ExecutionRequest): void;
executor: Executor;
setExecutor(executor: Executor): void;
}
export interface OnSubgraphExecuteDonePayload {
result: AsyncIterable<ExecutionResult> | ExecutionResult;
setResult(result: AsyncIterable<ExecutionResult> | ExecutionResult): void;
}
export type OnSubgraphExecuteDoneHook = (payload: OnSubgraphExecuteDonePayload) => MaybePromise<Maybe<OnSubgraphExecuteDoneResult | void>>;
export type OnSubgraphExecuteDoneResultOnNext = (payload: OnSubgraphExecuteDoneOnNextPayload) => MaybePromise<void>;
export interface OnSubgraphExecuteDoneOnNextPayload {
result: ExecutionResult;
setResult(result: ExecutionResult): void;
}
export type OnSubgraphExecuteDoneResultOnEnd = () => MaybePromise<void>;
export type OnSubgraphExecuteDoneResult = {
onNext?: OnSubgraphExecuteDoneResultOnNext;
onEnd?: OnSubgraphExecuteDoneResultOnEnd;
};