@graphql-mesh/fusion-runtime
Version:
Runtime for GraphQL Mesh Fusion Supergraph
72 lines (71 loc) • 3.12 kB
text/typescript
import type { DocumentNode, GraphQLSchema } from 'graphql';
import type { TransportEntryAdditions } from '@graphql-hive/gateway';
import type { TransportContext, TransportEntry } from '@graphql-mesh/transport-common';
import type { OnDelegateHook } from '@graphql-mesh/types';
import type { SubschemaConfig } from '@graphql-tools/delegate';
import type { IResolvers, MaybePromise, TypeSource } from '@graphql-tools/utils';
import { DisposableSymbols } from '@whatwg-node/disposablestack';
import { getOnSubgraphExecute, type OnSubgraphExecuteHook, type Transports } from './utils.cjs';
export declare function ensureSchema(source: GraphQLSchema | DocumentNode | string): GraphQLSchema;
export type UnifiedGraphHandler = (opts: UnifiedGraphHandlerOpts) => UnifiedGraphHandlerResult;
export interface UnifiedGraphHandlerOpts {
unifiedGraph: GraphQLSchema;
additionalTypeDefs?: TypeSource;
additionalResolvers?: IResolvers<unknown, any> | IResolvers<unknown, any>[];
onSubgraphExecute: ReturnType<typeof getOnSubgraphExecute>;
transportEntryAdditions?: TransportEntryAdditions;
/**
* Whether to batch the subgraph executions.
* @default true
*/
batch?: boolean;
}
export interface UnifiedGraphHandlerResult {
unifiedGraph: GraphQLSchema;
transportEntryMap: Record<string, TransportEntry>;
subschemas: SubschemaConfig[];
additionalResolvers: IResolvers[];
}
export interface UnifiedGraphManagerOptions<TContext> {
getUnifiedGraph(ctx: TransportContext): MaybePromise<GraphQLSchema | string | DocumentNode>;
handleUnifiedGraph?: UnifiedGraphHandler;
onSchemaChange?(unifiedGraph: GraphQLSchema): void;
transports?: Transports;
transportEntryAdditions?: TransportEntryAdditions;
/** Schema polling interval in milliseconds. */
pollingInterval?: number;
additionalTypeDefs?: TypeSource;
additionalResolvers?: IResolvers<unknown, TContext> | IResolvers<unknown, TContext>[];
transportContext?: TransportContext;
onSubgraphExecuteHooks?: OnSubgraphExecuteHook[];
onDelegateHooks?: OnDelegateHook<unknown>[];
/**
* Whether to batch the subgraph executions.
* @default true
*/
batch?: boolean;
}
export declare class UnifiedGraphManager<TContext> {
private opts;
private batch;
private handleUnifiedGraph;
private unifiedGraph;
private lastLoadedUnifiedGraph;
private onSubgraphExecuteHooks;
private currentTimeout;
private inContextSDK;
private initialUnifiedGraph$;
private disposableStack;
private _transportEntryMap;
private _transportExecutorStack;
constructor(opts: UnifiedGraphManagerOptions<TContext>);
private pausePolling;
private continuePolling;
private ensureUnifiedGraph;
private getAndSetUnifiedGraph;
getUnifiedGraph(): MaybePromise<GraphQLSchema>;
getContext<T extends {} = {}>(base?: T): MaybePromise<T>;
getTransportEntryMap(): MaybePromise<Record<string, TransportEntry<Record<string, any>>>>;
invalidateUnifiedGraph(): MaybePromise<true>;
[DisposableSymbols.asyncDispose](): Promise<void>;
}