UNPKG

@envelop/execute-subscription-event

Version:

Utilities for hooking into the [ExecuteSubscriptionEvent](<https://spec.graphql.org/draft/#ExecuteSubscriptionEvent()>) phase.

15 lines (14 loc) 958 B
import { SubscriptionArgs } from 'graphql'; import { DefaultContext, Plugin, PromiseOrValue } from '@envelop/core'; export type ContextFactoryOptions = { /** The arguments with which the subscription was set up. */ args: SubscriptionArgs; }; 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>;