import type { DocumentNode, GraphQLResolveInfo, GraphQLSchema, SelectionSetNode } from 'graphql'; import type { PromiseOrValue } from 'graphql/jsutils/PromiseOrValue.cjs'; import type { Plugin } from '@envelop/core'; import type { BatchDelegateOptions } from '@graphql-tools/batch-delegate'; import type { CreateProxyingResolverFn, IDelegateToSchemaOptions, MergedTypeConfig, SubschemaConfig, Transform } from '@graphql-tools/delegate'; import type { ExecutionRequest, Executor, IResolvers, MaybePromise } from '@graphql-tools/utils'; import type { TypedDocumentNode } from '@graphql-typed-document-node/core'; import * as YamlConfig from './config.cjs'; import type { MeshPubSub } from './pubsub.cjs'; import type { IMeshStore } from './store.cjs'; export * from './pubsub.cjs'; export { jsonSchema } from './config-schema.cjs'; export { YamlConfig }; export type MeshSource = { schema: GraphQLSchema; executor?: Executor; contextVariables?: Record; batch?: boolean; merge?: Record; }; export interface KeyValueCacheSetOptions { /** * Specified in **seconds**, the time-to-live (TTL) value limits the lifespan * of the data being stored in the cache. */ ttl?: number | null; } export interface KeyValueCache { get(key: string): MaybePromise; set(key: string, value: V, options?: KeyValueCacheSetOptions): MaybePromise; delete(key: string): MaybePromise; getKeysByPrefix(prefix: string): MaybePromise; } export type MeshHandlerOptions = { name: string; config: THandlerConfig; baseDir: string; cache: KeyValueCache; pubsub: MeshPubSub; store: IMeshStore; logger: Logger; importFn: ImportFn; }; export type GetMeshSourcePayload = { fetchFn: MeshFetch; }; export interface MeshHandler { getMeshSource: (payload: GetMeshSourcePayload) => Promise; } export interface MeshHandlerLibrary { new (options: MeshHandlerOptions): MeshHandler; } export interface MeshTransformOptions { apiName: string; config: Config; baseDir: string; cache: KeyValueCache; pubsub: MeshPubSub; importFn: ImportFn; logger: Logger; } export interface MeshTransformLibrary { new (options: MeshTransformOptions): MeshTransform; } export interface MeshTransform extends Transform { noWrap?: boolean; } export type Maybe = null | undefined | T; export interface MeshMergerOptions { cache: KeyValueCache; pubsub: MeshPubSub; logger: Logger; store: IMeshStore; } export interface MeshMergerLibrary { new (options: MeshMergerOptions): MeshMerger; } export interface MeshMergerContext { rawSources: RawSourceOutput[]; typeDefs?: DocumentNode[]; resolvers?: IResolvers | IResolvers[]; } export interface MeshMerger { name: string; getUnifiedSchema(mergerContext: MeshMergerContext): SubschemaConfig | Promise; } export type MeshPluginOptions = TConfig & { logger: Logger; cache: KeyValueCache; pubsub: MeshPubSub; baseDir: string; importFn: ImportFn; }; export type MeshPluginFactory = (options: MeshPluginOptions) => Plugin; export type OnDelegateHookPayload = Partial> & Partial> & { sourceName: string; typeName: string; fieldName: string; }; export type OnDelegateHook = (payload: OnDelegateHookPayload) => PromiseOrValue; export type OnDelegateHookDonePayload = { result: any; setResult: (result: any) => void; }; export type OnDelegateHookDone = (payload: OnDelegateHookDonePayload) => PromiseOrValue; export type MeshPlugin = Plugin & { onFetch?: OnFetchHook; onDelegate?: OnDelegateHook; [Symbol.asyncDispose]?: () => PromiseLike | void; }; export type MeshFetch = (url: string, options?: MeshFetchRequestInit, context?: any, info?: GraphQLResolveInfo) => MaybePromise; export type MeshFetchRequestInit = Omit & { headers?: Record; }; export interface OnFetchHookPayload { url: string; setURL(url: URL | string): void; options: MeshFetchRequestInit; setOptions(options: MeshFetchRequestInit): void; context: TContext; info: GraphQLResolveInfo; fetchFn: MeshFetch; setFetchFn: (fetchFn: MeshFetch) => void; executionRequest?: ExecutionRequest; logger: Logger; requestId?: string; endResponse: (response$: MaybePromise) => void; } export interface OnFetchHookDonePayload { response: Response; setResponse: (response: Response) => void; } export type OnFetchHookDone = (payload: OnFetchHookDonePayload) => MaybePromise; export type OnFetchHook = (payload: OnFetchHookPayload) => MaybePromise; export type RawSourceOutput = { name: string; schema: GraphQLSchema; executor?: Executor; transforms: MeshTransform[]; contextVariables: Record; handler: MeshHandler; batch: boolean; merge?: Record; createProxyingResolver: CreateProxyingResolverFn; }; export type GraphQLOperation = TypedDocumentNode | string; export type ImportFn = (moduleId: string, noCache?: boolean) => Promise; export type LazyLoggerMessage = (() => any | any[]) | any; export type Logger = { name?: string; log: (...args: any[]) => void; warn: (...args: any[]) => void; info: (...args: any[]) => void; error: (...args: any[]) => void; debug: (...lazyArgs: LazyLoggerMessage[]) => void; child: (name: string | Record) => Logger; addPrefix?: (prefix: string | Record) => Logger; }; export type SelectionSetParam = SelectionSetNode | DocumentNode | string | SelectionSetNode; export type SelectionSetParamOrFactory = ((subtree: SelectionSetNode) => SelectionSetParam) | SelectionSetParam; export type InContextSdkMethodBatchingParams = { key: TKey; argsFromKeys: (keys: TKey[]) => TArgs; valuesFromResults?: (results: TDefaultReturn, keys: TKey[]) => TReturn | TReturn[]; }; export type InContextSdkMethodRegularParams = { args?: TArgs; valuesFromResults?: (results: TDefaultReturn) => TReturn | TReturn[]; }; export type InContextSdkMethodCustomSelectionSetParams = { selectionSet: SelectionSetParamOrFactory; info?: GraphQLResolveInfo; }; export type InContextSdkMethodInfoParams = { info: GraphQLResolveInfo; }; export type InContextSdkMethodAutoSelectionSetParams = { autoSelectionSetWithDepth: number; info?: GraphQLResolveInfo; }; export type InContextSdkMethodParams = { root?: any; context: TContext; } & (InContextSdkMethodCustomSelectionSetParams | InContextSdkMethodInfoParams | InContextSdkMethodAutoSelectionSetParams) & (InContextSdkMethodBatchingParams | InContextSdkMethodRegularParams); export type InContextSdkMethod = (params: InContextSdkMethodParams) => Promise;