UNPKG

@envelop/execute-subscription-event

Version:
15 lines (14 loc) 962 B
import type { ExecutionArgs } from 'graphql'; import type { DefaultContext, Plugin, PromiseOrValue } from '@envelop/core'; export type ContextFactoryOptions = { /** The arguments with which the subscription was set up. */ args: ExecutionArgs; }; export type ContextFactoryHook<TContextValue> = { /** Context that will be used for the "ExecuteSubscriptionEvent" phase. */ contextPartial: Partial<TContextValue>; /** Optional callback that is invoked once the "ExecuteSubscriptionEvent" phase has ended. Useful for cleanup, such as tearing down database connections. */ onEnd?: () => void; }; export type ContextFactoryType<TContextValue = DefaultContext> = (options: ContextFactoryOptions) => PromiseOrValue<ContextFactoryHook<TContextValue> | void>; export declare const useExtendContextValuePerExecuteSubscriptionEvent: <TContextValue extends Record<any, any>>(createContext: ContextFactoryType<TContextValue>) => Plugin<TContextValue>;